Getting error Route not defined at LARAVEL - php

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.

Related

Laravel Route not defined error in resource controller

I have route file defined as follows...
Route::get('pincodes/export', 'PincodeController#export'); Route::resource('pincodes','PincodeController');
I have a controller called 'PincodeController' where the default functions works without any issue. I wanted to add a new function called 'export' in this controller. I tried {{ route('pincodes.export') }} in my blade file to generate link to this page... and it throws the following error...
Facade\Ignition\Exceptions\ViewException Route [pincodes.export] not defined. (View: /Users/tst/Desktop/www/laravel/project/resources/views/pincode/index.blade.php)
but if i access the url directly in browser it works fine. why is that ?
You need to specifically name the route:
Route::get('pincodes/export', 'PincodeController#export')->name('pincodes.export');
If you are using Laravel 5.5+, change export route like this
Route::get('pincodes/export', 'PincodeController#export')->name('export');
use route function in your blade file like
route('export')

laravel 7 Auth::routes don't work for disabling registration and password reset

I've a project upgraded from laravel 5.4 to 7.6.2, everything is ok, except that I'm unable to remove registration and password reset routes from blade using has('password.request').
As per documentation, I use below options as first line inside the web.php route file:
Auth::routes(['register' => false, 'request' => false, 'reset' => false]);
the problem is that the below code is still executed:
#if (Route::has('password.request'))
<a class="btn btn-link" href="{{ route('password.request') }}">
{{ __('Forgot Your Password?') }}
</a>
#endif
As suggested around also on stackoverflow, I also removed the ResetPasswordController.php, RegisterController.php and the ForgotPasswordController.php but after runing "composer dump" the route is still available when I call has('password.request').
Obivioulsy if I click on reset request the route don't exist and the user is unable to reset the password, but I want understand if I did it in the right way. My doubt is mostly arount has('password.request'), why return always true?
ok, after two hour of digging... I just discovered that for some reason I had TWO different calls to Auth::routes().
The first one is mine call with all corrects parameters, the second one was at the end of the web.php route file and is empty! so I "reset" my own setting :(
I don't know how can be happen... probabily is a mistake made during the migration process from 5.4 to 7.x

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

How to inspect the current Named Route using Laravel 5.2

according to the Laravel 5.5 docs, there is a named() method for accessing route names:
if ($request->route()->named('profile')) {
//
}
Inspecting the source, I learned that this named method simply fetches the 'as' property of the action object:
$this->action['as']
My problem is I'm stuck using Laravel 5.2, which doesn't have a named() method. I can't use route()->action['as'] in my blade template, because the actionobject is protected. Is there an equivalent getter method in 5.2, to check the name of the current route? I want to flow control in my blade.php file like this:
#if(route()->action['as'] == 'blog.edit')
//
#endif
Maybe I missed it, but I didn't see anything in the Laravel 5.2 docs: https://laravel.com/docs/5.2/routing#named-routes
I succeeded in checking the route using
#if(request()->is('blog/add'))
//
#endif
But that is using the route URI. I prefer to use the route name instead as it's less clunky
answer from Gitter courtesy of Ben Johnson:
#if(Route::currentRouteName() == 'blog.edit')
//
#endif

Method [show] does not exist in laravel 4.2

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']]);

Categories