Method [show] does not exist in laravel 4.2 - php

I want to pass multiple parameter from href and want to get with Input::get() in my function. I get this error :
bad method call exception Method [show] does not exist error.
My route is: Route::get('workorder/test', 'WorkOrderController#test'); and passing on this way
<a class="btn btn-primary btn-xs" title="Edit" href="{{URL::to('workorder/test?work_order_id='.$item->id.'&site_office_id='.$item->site_office_id)}}">
<i class="fa fa-edit text-white"></i>
</a>
I want to get from my function:
public function test() {
echo Input::get('work_order_id');exit;
}
These are my routes for the given controller:
Route::resource('workorder', 'WorkOrderController');
Route::get('workorder/filter', 'WorkOrderController#filter');
Route::post('workorder/proceedworkorder', 'WorkOrderController#proceedworkorder');
Route::get('workorder/addworkorder', 'WorkOrderController#addworkorder');
Route::get('workorder/approve/{id?}', 'WorkOrderController#approve');
Route::get('workorder/decline/{id?}', 'WorkOrderController#decline');
Route::get('workorder/test', 'WorkOrderController#test');
I am not sure why I am getting this error.

Try removing:
Route::resource('workorder', 'WorkOrderController');
This method alone maps out all the normal RESTful endpoints. And is potentially overriding the test endpoint.
This single route declaration creates multiple routes to handle a
variety of RESTful actions on the photo resource. Likewise, the
generated controller will already have methods stubbed for each of
these actions, including notes informing you which URIs and verbs they
handle.
If you need to keep it I would put in:
Route::resource('workorder', 'WorkOrderController', ['except' => ['show']]);

Related

Route not defined php laravel5.5

I got an error : Route [admin/news] not defined I try to use #component in my create.blade.php
In my Controller I declare variable
public $route = 'admin/news' ;
In web.php
Route::post('admin/news/create', 'Admin\NewsController#store');
Route::resource('admin/news', 'Admin\NewsController');
In my html this return right Url
<a class="btn btn-success" href="{{ asset($route.'/create') }}">add</a>
<a class="btn btn-success" href="{{ route('news.create') }}">add</a>
I check my route by using php artisan r:l
It has a news.create
I try to use other routes both of these work fine not sure what's wrong with my create route
route('news.edit',$t->id)
route('news.destroy',$t->id)
the problem is in my create.blade.php I try to use #component by this
#component('layouts.submitform',
['id'=>'create','method'=> isset($edit) ? 'PUT' : 'POST' ,'action'=> isset($data->id) ? asset($route.'/'.$data->id) : route($route)]
)
You have $route set to admin/news. You say you want to go to the create page. You then say that the route is named news.create. So use news.create as the name when referencing it with the helper. Set $route to news.create.
You seem to want to use a URI and a route name. You have to decide which one you are going for.
Laravel Docs - Routing - Named Routes
Laravel Docs - Helpers - Url Helpers - route

Getting error Route not defined at LARAVEL

I installed a Git laravel (employee-mgmt-laravel5.4-adminlte)
Now I'm trying to export an invoice to excel but the route doesn't work and I'm getting this error : Route [facture-management.export] not defined.
This my button
<a class="btn btn-primary" href="{{ route('facture-management.create') }}">Ajouter factures</a> (this one work)
<a class="btn btn-primary" href="{{ route('facture-management.export') }}">excel</a> (this one is not working)
This is my route
Route::resource('facture-management', 'FactureManagementController');
Route::post('facture-management/search', 'FactureManagementController#search')->name('facture-management.search');
What is going wrong because .create and .update are working but why is .excel not working ?
In your FactureManagementController you should have an export method.
and then: Route::get('your-url', 'FactureManagementController#export');
Because you have a resource route, you have the index/create/show/edit/update/destroy methods, but export you have to create.
If you do have it defined, please post your controller.
I can see that you are using a laravel controller resource. Laravel controller resource comes with the create and update function by default. You are getting this error because facture-management#export is not defined in your controller. Check your facture-management controller and see if public function export() exists. If not, you need to create one and define its functions.

Route function meaning

I am having some difficulty understanding what this code is doing. could someone explain it to me? I saw some people using it to redirect user to another page with it but I don't understand this part here "['id'=>$data3->id]) ".
Here is the full code: (from view page)
<a href="{!! route('user.upload.image', ['id'=>$data3->id]) !!}">
Controller (how data3 is being passed to view):
public function getInfo($id) {
$data3=UserImage::where('user_id',$id)->get();
return view('view',compact('data3'));
Route:
Route::get('/userUpload/{user}/create1','CreateController#create1')->name('user.upload.iamge');
Route::get('user/show/{id}','HomeController#getInfo')->name("user.show");
create1 controller:
public function create1(personal_info $user){
return view('create1')->withUser($user);
}
Based on your routes
Route::get('/userUpload/{user}/create1','CreateController#create1')->name('user.upload.iamge');
Route::get('user/show/{id}','HomeController#getInfo')->name("user.show");
The first route has a parameter user which must be passed to it anytime the route is called.
The second one also has an id parameter which must also be passed to it.
Passing the parameter values to the routes can be done in many ways. Eg.
By using the route name:
<a href="{!! route('user.upload.image', ['user'=>$data3->id]) !!}">
This method requires you to pass all the parameters as an array with the parameter name as the key of the array.
You can also call the route like:
<a href="/userUpload/{$data3->id}/create1">
Which requires nothing since the parameter has been hardcoded into the url.
Any time you accept parameters in your route, to pass them to your controller or route function, the must be listed on the order in which they are arranged.
So your getInfo passes the id parameter it received from the route to the controller
public function getInfo($id) {
$data3=UserImage::where('user_id',$id)->get();
return view('view',compact('data3'));
}

Type error: Too few arguments to function laravel 5.4

I'm having an html href where I want to pass values to a controller method but it displays Type error: Too few arguments to function
HTML
<li><a href="{{route('sidebarSearch.show',['type'=>$all,'title'=>$title])}}">
<i class="fa fa-chevron-right"></i> all</a></li>
<li><a href="{{route('sidebarSearch.show',['type'=>$paid,'title'=>$title])}}">
<i class="fa fa-chevron-right"></i> paid</a></li>
<li><a href="{{route('sidebarSearch.show',['type'=>$free,'title'=>$title])}}">
<i class="fa fa-chevron-right"></i> free</a></li>
controller
public function show($type,$title)
{
//
}`
Probably you are missing the variable in the route declaration. Check the route name in your routes file to see it the code looks like that:
Route::get('/sidebarSearch/show/{type}/{title}', 'SidebarSearchController#show')->name('sidebarSearch.show');
Also run a php artisan route:cache and then php artisan route:list to check if the name column has a sidebarSearch.show declared with the right parameters.
If in your case you are referring to the show method of a resource (index, create, store, update, show etc) you can overrite the method by only adding the route above to your route files.
The solution was basically to use link_to_route() or link_to_action() and pass the parameters .

Laravel 5.1 custom method in controller

In a controller name tagController where I define a custom method
public function addTag($id)
{
$book = $id;
return view('tag.create', compact('book'));
}
In the route I define the custom route method
Route::get('tag/addTag/{$id}', 'tagController#addTag');
Route::resource('tag', 'tagController');
From my view I'm calling the controller method
<a class="btn btn-primary various" href="{{url('/tag/addTag', $tag->id)}}">Add Tag</a>
I'm getting the error every time
NotFoundHttpException in RouteCollection.php line 143:
This is routing problem but I don't understand to how to define a custom method in route and in resourceful controller. Please help to get rid of the error?
Thanks.
Remove the $ from the path
Route::get('tag/addTag/{id}', 'tagController#addTag');

Categories