The solution I found was working via GET
, passing the admin and other user parameters.
Creating a Route
The first thing I did was create a route for the template , which gets a GET
parameter containing the current user, then I direct the logic to a controller method called treatingOSideBarViaGET.php , which in turn calls the page method:
<?php
Route::get('suaURLPreferida/{whichUser}', 'tratandoOSideBarViaGET@page');
Generating the Controller
Now what's the fun part: D
In controller I define that page method that receives a parameter whichUser is responsible for returning the current user. Then inside the method I point to views and search for the template inicio.blade.php , in it I define a parameter php artisan make:controller tratandoOSideBarViaGET
, responsible for knowing if we are making a call from Admin or User :
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class tratandoOSideBarViaGET extends Controller
{
public function page($whichUser)
{
return view('inicio')->with('user', $whichUser);
}
}
Template
Finally, in the template I create a condition, if App\Http\Controllers\
is admin then $user
, or if $user
is user then @include('sidebarAdmin')
, if both return $user
does not show anything:
@if ($user == 'admin')
@include('sidebarAdmin')
@elseif ($user == 'usuario')
@include('sidebarUser')
@endif
Final considerations
Realize that this is not the only way to do this, but it would be a good practice to follow through with it. Understand you might as well do so:
<?php
Route::get('suaURLPreferida/{whichUser}', function ($whichUser) {
return view('inicio')->with('user', $whichUser);
});
I do not recommend this, because you are mixing the functions of the MVC, it is not the function of a route add a parameter to a view controller so I separated the responsibilities. Feel free to choose the best solution, just wanted to make my point clear.