I'm working on a Laravel project, where I have the following routes:
Route::group(['middleware' => ['web', 'auth'], 'prefix' => 'deliver'], function () {
Route::get("{pitch}/play", "DeliverController#play")->name("deliver.play");
Route::get('/', 'DeliverController#index')->name('deliver');
});
The route named deliver.play is being called like this:
<a href="{{ route("deliver.play", $pitch) }}">
<span class="glyphicon glyphicon-picture" data-toggle="tooltip" data-placement="top" title="Go to Playmode"></span>
</a>
As you can see, I pass the $pitch parameter to the route, however, on execution, the following error pops up:
ErrorException in UrlGenerationException.php line 17:
Missing required parameters for [Route: deliver.play] [URI: deliver/{pitch}/play].
Which normally means the {pitch} param isn't given, however, in the URL bar of my browser the param is there, giving me the complete URL of
http://localhost:8000/deliver/empty-pitch-13/play
So how is it possible for Laravel to not see the parameter im passing on to the route? Or is there something that I'm missing?
Thanks.
Edit:
I forgot to add the controller that the route links to. Here it is:
public function play(Pitch $pitch)
{
if ($pitch->hasPresentation()) {
$presentation = head($pitch->presentations);
return view("deliver.play.index", $presentation);
}
return redirect()->route('slides.create', $pitch);
}
Try this:
<a href="{{ route('deliver.play', ['pitch' => $pitch]) }}">
and add the pitch params to the function like so
Route::group(['middleware' => ['web', 'auth'], 'prefix' => 'deliver'], function () {
Route::get("{pitch}/play", "DeliverController#play", function($pitch){
//
})->name("deliver.play");
Route::get('/', 'DeliverController#index')->name('deliver');
});
Related
I got error that says
Method App\Http\Controllers\Frontend\Atribut\AtributDashboardController::deleteData/{id} does not exist.
I write my routes like this :
Route::group([
'prefix' => 'atribut',
'as' => 'atribut.'
], function () {
Route::group(['prefix' => 'tabHome', 'as' => 'tabHome.'], function () {
Route::get('', [AtributDashboardController::class, 'showTab'])->name('showTab');
Route::post('', [AtributDashboardController::class, 'addData'])->name('addData');
Route::get('', [AtributDashboardController::class, 'deleteData/{id}'])->name('deleteData');
});
in the controller i also already write these :
public function deleteData($id)
{
$this->inpData->deleteData($id);
return redirect('atribut/tabHome');
}
i call $this->inpData->deleteData($id) from my models :
public function deleteData($id)
{
DB::table('inp_datas')->where('id', $id)->delete();
}
this is the button action when delete button pressed:
#forelse ($dataDisplay as $data)
<tr>
<td>{{$data->name}}</td>
<td>
Delete
</td>
</tr>
#empty
#endforelse
why it says the method does not exist?
As you can see in the documentation, the Route first argument is route name, and in the array you have to specify class and its method.
Why it says the method does not exist?
In your AttributDashboardController you have deleteData method, not deleteData/{id}. The deleteData/{id} is more likely to be a route name in your case.
So for your example, delete route should look like this:
Route::get('deleteData/{id}', [AtributDashboardController::class, 'deleteData'])->name('deleteData');
or:
Route::get('{id}', [AtributDashboardController::class, 'deleteData'])->name('deleteData');
Laravel is smart enough to pass the {id} parameter to your deleteData method as $id argument.
HTTP DELETE
Also, if you want to make delete at this route, you will probably benefit from reading about available router methods, and especially HTTP DELETE.
My controllers which are HomeController and BlogController in Admin folder. My views like:
/admin
index.blade.php
/blog
index.blade.php
I want to call /admin0admin url to /resources/views/admin/index.blade.php.
I want to call /admin0admin/blog url to /resources/views/admin/blog/index.blade.php
Here how i call in view:
<a href="{{ route('admin0admin.blog') }}" class="br-menu-link">
And my routes like:
Route::group(['namespace' => 'Admin', 'prefix' => 'admin0admin'], function () {
Route::get('/', 'HomeController#index')->name('index');
Route::group(['prefix' => 'blog'], function () {
Route::get('/', 'BlogController#index')->name('index');
});
});
And my BlogController index method:
return view('admin.blog.index');
I got an 404 not found error.
Route [admin0admin.blog] not defined
Laravel Version is : 5.6.*
You need to name the route admin0admin.blog, not index. prefix does not affect names of routes, so you need to write it out.
AdminLTE Laravel template screenshoot:
how can i direct the link into my page in folder lapor/one.blade.php and lapor/two.blade.php?
<li class="treeview">
<a><i class='fa fa-file'></i> <span>Laporan</span> <i class="fa fa-angle-left pull-right"></i></a>
<ul class="treeview-menu">
<li>One</li>
<li>Two</li>
</ul>
</li>
Make a route like below
Route::get('one', function () {
return view('lapor.one');
});
Route::get('two', function () {
return view('lapor.two');
});
And link it like below
<li>One</li>
I would group your adminLTE routes:
Route::group(['prefix' => 'admin', 'as' => 'admin.'], function()
{
Route::get('/', ['as' => 'dashboard', 'uses' => 'AdminController#index']);
Route::get('users', ['as' => 'user', 'uses' => 'AdminController#users']);
});
We prefixed those routes with /admin/ or whatever you want to call it. Then we prefixed their name with admin (using 'as').
Now get a specific route url:
{{ route('admin.dashboard') }}
Why do it like this?
Naming your routes is very important because if the route url changes and your app has hardcored urls (like url('/admin/dashboard') your entire application will break. With named routes this wont happen.
You can do it in three step:
make a function in your controller.like below
publice function functionName(){
return view('yourpagename(one)');
}
go to routes folder open web.php and connect with your controller function in routes. like
Route::get('page-name', 'controllerName#functionName');
add this url to your view page link tag
{{URL::to('page-name')}}
Hope it will works fine.
Before going to redirect the page two steps you need to do :
Step 1:
Define Methods in controller(named as SampleController) for example:
//Controller Name:SampleController
// Method Names defined in controller :lapor1,lapor2
//Method 1
public function lapor1(){
return view('lapor.one');
}
//Method 2
public function lapor2(){
return view('lapor.two');
}
Step :2
Define Routes for the pages like below:
Route::get('lapor1', ['as' => 'laporone','uses'=>'SampleController#lapor1']);
Route::get('lapor2', ['as' => 'laportwo','uses'=>'SampleController#lapor2']);
Step 3:
Link up to view pages now:
<li>One</li>
<li>Two</li>
i am trying to access one route like pages.trashmultiple this in my view. But its throwing error of Route [pages.trashmultiple] not defined.. Here is how my view looks like:
{!!Form::open([
'method' => 'put',
'route' => 'pages.trashmultiple'
])!!}
<th class="table-checkbox">
<input type="checkbox" class="group-checkable" data-set="#sample_3 .checkboxes"/>
</th>
{!!Form::close()!!}
This is how my controller looks like:
public function trashmultiple(Request $request){
//return "trash multiple page";
return Input::all();
}
And this is how my routes look like:
Route::group(['middleware' => ['web']], function () {
Route::get('pages/trash', 'PagesController#trashpage');
Route::get('pages/movetotrash/{id}', 'PagesController#movetotrash');
Route::get('pages/restore/{id}', 'PagesController#restore');
Route::get('pages/trashmultiple', 'PagesController#trashmultiple'); //this is not working
Route::resource('pages', 'PagesController');
});
When i load my url http://localhost:8888/laravelCRM/public/pages it shows me this below error:
ErrorException in UrlGenerator.php line 307:
Route [pages.trashmultiple] not defined. (View: /Applications/MAMP/htdocs/laravelCRM/resources/views/pages/pages.blade.php)
I want to know why i am unable to access the pages.trashmultiple when i have already defined it.
Is there any way i can make it accessible through pages.trashmultiple?
Thank you! (in advance)
chnage your route to like this:
Route::get('pages/trashmultiple', 'PagesController#trashmultiple');
To
Route::get('pages/trashmultiple', [
'as' => 'pages.trashmultiple', 'uses' => 'PagesController#trashmultiple'
]);
Change your route so that it becomes:
Route::get('pages/trashmultiple',
['as'=>'pages.trashmultiple',
'uses'=>'PagesController#trashmultiple']);
i have route like this :
Route::controller('/users', 'AdminUsersController', array(
"revokeUser" => "admin.user.revoke_user",
));
and this is my controller
public function revokeUser($nationalCode)
{
dd("I'm in");
}
but when im going to use route i have exception route not defined
<a class="btn btn-warning btn-sm" href="{{ URL::route('admin.user.revoke_user',array($user->national_code)) }}">
Click here
</a>
exception :
Route [admin.user.revoke_user] not defined. (View:
/var/www/pedram.dev/blog/app/views/admin/users/index.blade.php)
You can use this in routes.php
Route::match(['get', 'post'], '/users/{nationalCode}', ['as' => 'admin.user.revoke_user', 'uses' => 'AdminUsersController#revokeUser']);
EDIT you are getting error because your function takes argument and in your route definition you haven't defined argument. So you need :
Route::controller('/users/{nationalCode}', 'AdminUsersController', array(
"revokeUser" => "admin.user.revoke_user",
));