The solution I found was to work via GET
, passing the parameters admin and another user.
Creating a Route
The first thing I did was create a route to the template, that receives a parameter GET
containing the current user, then I direct the logic to a controller called treatingOSideBarViaGET.php, which in turn calls the method page:
<?php
Route::get('suaURLPreferida/{whichUser}', 'tratandoOSideBarViaGET@page');
Generating the Controller
Done that I’ll get one controller using the command php artisan make:controller tratandoOSideBarViaGET
that will appear in the directory App\Http\Controllers\
.
Now that comes the fun part :D
In the controller I define that method page that receives a parameter whichUser responsible for returning the current user. So within the method I point to views and search by template inicio.blade.php, in it I define a parameter $user
, responsible for knowing if we are making a call from Admin or of 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 at the template I create a condition if $user
for admin then @include('sidebarAdmin')
, or if $user
for user then @include('sidebarUser')
, if they both return false
shows nothing:
@if ($user == 'admin')
@include('sidebarAdmin')
@elseif ($user == 'usuario')
@include('sidebarUser')
@endif
Final considerations
Note that this is not the only way to do this, but it would be good practice for you to follow 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 MVC, it is not a function of a route add a parameter to a view, this is up to the controller so I separated the responsibilities. Feel free to choose the best solution, just wanted to make clear my point.
The mistake was another, I was directing the wrong view, not the one I was testing. Sorry and thanks for the attention.
– Raylan Soares