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",
));
Related
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');
});
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'm working in a laravel application and trying to implement delete() method in a controller but it doesn't work.
This is the Error:
BadMethodCallException in Controller.php line 283: Method [delete] does not exist.
Here is my view (buss.blade.php)
<a href="{!! URL::to('delete_bus', array($u->id)) !!}">
<span class="glyphicon glyphicon-minus"></span>
</a>
Here is my Route:
Route::get('delete_bus/{id}', array('uses' => 'adminController#delete'));
and it exists in app/resources/admin/buss.blade.php
And Here is my Controller Method
public function delete_bus($id) {
$reg = Business::find($id);
$reg->delete();
return Redirect::to('buss')->with('del', 'Sucessfully Deleted!');
}
You named your controller method delete_bus, but your trying to route to delete method. Change your route to this:
Route::get('delete_bus/{id}', array('uses' => 'adminController#delete_bus'));
And your controller should be called with capital letters, so this could be potential bug as well.
I have this route :
// work
Route::resource('work', 'WorkController');
Route::get('work/{id}/delete', array('as' => 'admin.work.delete', 'uses' => 'WorkController#confirmDestroy'))
->where('id', '[0-9]+');
and my controller WorkController is residing at App/Controllers/Admin
in the view I call it like this:
<span class="glyphicon glyphicon-book"></span> <br/>Work
and I get this error:
Error Message: Class App\Controllers\Admin\Work does not exist
What is wrong with my code? I have used the same approach for pages, users and menus and it worked.
Can you confirm what is the name of controller file in App\Controllers\Admin?. Also your route should be
// work
Route::group(array('prefix' => 'admin', function()
{
Route::resource('work', 'WorkController');
Route::get('work/{id}/delete', array('as' => 'admin.work.delete', 'uses' => 'WorkController#confirmDestroy'))
->where('id', '[0-9]+');
});