I start creating my application
- Install laravel 5 with composer
- php artisan migrate ---> ok
- php artisan make:auth ---> ok
- php artisan make:controller > AboutController --> ok
Result: I have "Home" page (secure page need authentication) and public page, "About"
The route file :
<?php
Route::get('/', function () {
return view('welcome');
});
Route::auth();
Route::get('/about', 'AboutController@index');
Route::get('/home', 'HomeController@index');
....
?>
The About controller is like this:
<?php namespace App\Http\Controllers; use App\Http\Requests; use
Illuminate\Http\Request;
class AboutController extends Controller {
public function __construct() {
}
public function index() {
return view('about');
}
}
This is my about.blade.php
file:
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row">
<div class="col-md-10 col-md-offset-1">
<div class="panel panel-default">
<div class="panel-heading">About</div>
<div class="panel-body">
About page!
</div>
</div>
</div>
</div>
</div>
@endsection
When I'm logged out:
Everything is fine, and I can access the About page with no problem. The home page needs login, nice.
When I am logged in:
I can access to Home page, that's OK.
But when I access the about page, I get an error on the view page something like:
FatalErrorException in AliasLoader.php line 63: Maximum function nesting level of '100' reached, aborting!
If I put: $this->middleware('auth');
in the About page, that's fine, but I don't want to do that.
I have tried all of this:
<?php
............
//$this->middleware('auth');
//$this->middleware('auth', ['only' => 'create']);
//$this->middleware('auth', ['only' => ['create', 'edit', 'destroy']]);
//$this->middleware('guest', ['except' => 'index']);
//$this->middleware('guest', ['except' => ['index', 'create']]);
//$this->middleware('guest');
........
?>
But the problem persisted.
Its look like this page needs middleware, so , I did this:
<?php
namespace App\Http\Controllers;
use App\Http\Requests;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class AboutController extends Controller {
public function __construct() {
if (Auth::check()) {
$this->middleware('auth');
}
else {
$this->middleware('guest');
}
}
public function index() {
return view('about');
}
}
?>
In this case it works fine, so I want to know if my solution is good, or if I'm wrong.