How to get user id properly?, This is error message Missing required parameter for [Route: user.currentRequest] [URI: user/user-current-request/{user}] [Missing parameter: user]
An User has many relationship with Request, and the url will be user-current-request{user-id}
//layouts.app
<li class="nav-item">
<a class="nav-link" href="{{ route('user.currentRequest') }}">Current Request</a>
</li>
Route::group(['prefix'=>'user', 'middleware'=>['isUser','auth']], function(){
Route::get('user-current-request/{user}', [UserController::class, 'currentRequest'])->name('user.currentRequest');
});
function currentRequest(User $user)
{
dd($user);
return view('dashboards.users.currentRequest');
}
Your route in Layouts.app need params.
<li class="nav-item">
<a class="nav-link" href="{{ route('user.currentRequest', $user) }}">Current Request</a>
</li>
If you want to give this params in layout you have to do it in the providers / appserviceprovider
Related
I don't know why the error is being thrown, because the route already exists.
master.blade.php:
<!-- Nav Item - Transaksi -->
<li class="nav-item">
<a class="nav-link" href="{{route('transaksi.index')}}">
<i class="fas fa-fw fa-folder"></i>
<span>Transaksi</span></a>
</li>
web.blade.php:
Route::resource('transaksi','TransaksiController');
TransaksiController:
public function index()
{
$data = DB::table('tbl_transaksi')
->where('tbl_transaksi.nama_peminjam','like',"%{$request->keyword}%")
->paginate(20);
return view('admin.transaksi.index',['data'=>$data]);
}
The error:
Symfony\Component\Routing\Exception\RouteNotFoundException
Route [transaksi.index] not defined. (View: C:\xampp\htdocs\SistemPerpustakaan\resources\views\admin\master.blade.php)
http://localhost:8000/dashboard
resolved, I just forgot to delete the route with the same name
I have the code below in my view, but when i route to the page, the tab isn't showing as active. I search for this on answer on SO but it wouldn't solve my problem..
What am i not doing right?
I am using laravel version 5.6
VIew
<ul id="main-menu-navigation" data-menu="menu-navigation" class="nav navbar-nav">
<li class="nav-item {{ Request::path() == '/admin/dashboard/foods/all' ? 'active' : '' }}"><a href="/admin/dashboard/foods/all" class="nav-link">
<img src="/images/menubar/items.png" width="30px" height="30px" border="0" alt="Module Icon"/>
<span>Food Items</span></a>
</li>
</ul>
First i recommend you to put the logic in a directive, so the html look creaner and the logic is separated from the view.
In your AppServiceProvider you just put this
Blade::directive('menuActive',function($expression) {
//explode the '$expression' string to the varibles needed
list($route, $class) = explode(', ', $expression);
//then we check if the route is the same as the one we are passing.
return "{{ request()->is({$route}) ? {$class} : '' }}";
});
know in your view you just add
<ul id="main-menu-navigation" data-menu="menu-navigation" class="nav navbar-nav">
<li class="nav-item #menuActive('admin/dashboard/foods/all', 'active')"><a href="/admin/dashboard/foods/all" class="nav-link">
<img src="/images/menubar/items.png" width="30px" height="30px" border="0" alt="Module Icon"/>
<span>Food Items</span></a>
</li>
I'm not sure what Request::path() is returning, but it doesn't match your check for /admin/dashboard/foods/all (honestly, likely an issue with leading /)
Also, there is a method called is() on the request() helper that determines if the current route matches a given value, so use as:
<li class="nav-item {{ request()->is('admin/dashboard/foods/all') ? 'active' : '' }}"> ...
And it should work.
I want to call variable to views in laravel, but something not working
here is my controller
public function index($id,$slugify, Request $request,WiuCookie $wcookie)
{
$user = ActionUsers::where('id', $id)->first();
$petition = Petitions::where('slug',$slugify)->first();
$isSigned = $wcookie->checkId($petition->id);
return view('layouts.master',compact('user','petition','isSigned'));
}
and here is my view
#if($isSigned)
<li>
<a href="#">
{{$user->name}}
</a>
</li>
#else
<li>
<a href="#">
register
</a>
</li>
<li>
<a href="#">
log-in
</a>
</li>
#endif
and error is Undefined variable: user
return view('layouts.master',compact(['user'=>$user,'petition'=>$petition,'isSigned'=>isSigned]));
It just works for me perfectly.
Try this:
$compactData=array('user','petition','isSigned');
return View::make('layouts.master', compact($compactData));
try this in passing remove compact and pass using with
->with('user',$user)
i am updating my application from laravel 5.2 to 5.3. Most of the things seems to work fine.
But i dont know what is happening but when i am trying to define route in anchor tag, its not working. I have done something similar to this:
<a href="{{route('backend.pages.index')}}" class="nav-link ">
<span class="title">All Pages</span>
</a>
Its showing error Route [backend.pages.index] not defined.. Here is how the created the route.
Route::group(['middleware' => ['web']], function () {
Route::resource('backend/pages','Backend\PagesController');
});
I have a template called 'mainmenu.blade.php' in which i have use this route. This mainmenu is called in main structure through #include('layouts.backend.backendstructure.mainmenu').
Is routing method is changed in laravel 5.3? Or is there any mistake from my side?
Thank you!(Advance)
The problem here is
{{route('backend.pages.index')}}
instead use
<a href="{{route('backend/pages')}}" class="nav-link ">
<span class="title">All Pages</span>
</a>
The route is defined as backend/pages. To return view add a method in PagesController and return the view there.
Route::group(['middleware' => ['web']], function () {
Route::resource('backend/pages','Backend\PagesController#dummymethod');
});
Dummy method
public function dummymethod
{
return view('backend.pages.index');
}
Edit
I think you're looking for something like this
Route::resource('backend/pages','Backend\PagesController', ['names' => ['index' => 'backend.pages.index']]);
Check the docs here
You should write your code like this:
<a href="{{ route('backend/pages')}} " class="nav-link ">
<span class="title">All Pages</span>
</a>
or like this:
<a href="{{ url('backend/pages') }}" class="nav-link ">
<span class="title">All Pages</span>
</a>
Try:
<a href="/backend/pages" class="nav-link ">
<span class="title">All Pages</span>
</a>
https://laravel.com/docs/5.3/routing
You can try link with URL to like, I use in following manner
<a href="{{URL::to('backend/pages')}}" class="nav-link ">
<span class="title">All Pages</span>
</a>
Here is my nav-bar:
<div class="col-md-2">
<ul class="list-group-item">
<li><i class="fa fa-fw fa-file</i> All Post
</li>
<li><i class="fa fa-fw fa-plus-circle"></i> Create New Post</li>
<li><i class="fa fa-fw fa-tasks"></i> Manage Posts</li>
</ul>
</div>
and here is my route.php
Route::group(['prefix' => 'posts'], function(){
Route::get('', 'PostController#index');
Route::get('create', 'PostController#create');
Route::post('confirm', 'PostController#confirmation');
Route::get('{postID}', 'PostController#show');
Route::get('posts/manage', 'PostController#manage');});
I expect when I click on the "Manage Posts" button, it will redirect me to function manage() in my PostController.
But when I click on it, it redirects to a view which belongs to storage/framework/views which is show() in my PostController.
I don't know why and how to make it to the right url.
Can somebody help me with this one please?
Thank you.
First of all, your link links to /posts/management, not /posts/manage. Second, you already have the prefix posts for this route-group, so the route posts/manage will be available under the url /posts/posts/manage.
You also want to move the manage route before your {postID} route, because {postID} will just catch anything, so the router has to first check the manage-route, and only if it doesn't match, the catch-all route.
And you should control what is accepted as a valid postID using Route Parameters: Regular Expression Constraints.
Route::get('{postID}', 'PostController#show')->where('id', '[0-9]+');