i have an issue on my view edit.blade of my EmployeeCOntroller.
Edit.blade.php
<form method="PUT" action="{{ route('employees.update', $employee_detail->id) }}" aria-label="{{ __('Edit') }}" enctype="multipart/form-data">
web.php
Route::patch('/employee/{id}', 'EmployeeController#update')->name('employees.update');
Route::get('/employee/{id}', 'EmployeeController#destroy')->name('employees.delete');
EmployeeController
public function update(Request $request, $id)
i dont know why but the request to my destroy() function on my controller !!
i have done php artisan route:list
+--------+----------+-------------------------------------+--------------------------------+------------------------------------------------------------------------+----------------------------------------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+-------------------------------------+--------------------------------+------------------------------------------------------------------------+----------------------------------------------+
| | GET|HEAD | / | | Closure | web |
| | GET|HEAD | _debugbar/assets/javascript | debugbar.assets.js | Barryvdh\Debugbar\Controllers\AssetController#js | Barryvdh\Debugbar\Middleware\DebugbarEnabled |
| | GET|HEAD | _debugbar/assets/stylesheets | debugbar.assets.css | Barryvdh\Debugbar\Controllers\AssetController#css | Barryvdh\Debugbar\Middleware\DebugbarEnabled |
| | DELETE | _debugbar/cache/{key}/{tags?} | debugbar.cache.delete | Barryvdh\Debugbar\Controllers\CacheController#delete | Barryvdh\Debugbar\Middleware\DebugbarEnabled |
| | GET|HEAD | _debugbar/clockwork/{id} | debugbar.clockwork | Barryvdh\Debugbar\Controllers\OpenHandlerController#clockwork | Barryvdh\Debugbar\Middleware\DebugbarEnabled |
| | GET|HEAD | _debugbar/open | debugbar.openhandler | Barryvdh\Debugbar\Controllers\OpenHandlerController#handle | Barryvdh\Debugbar\Middleware\DebugbarEnabled |
| | GET|HEAD | admin | admin | App\Http\Controllers\Back\AdminController#index | web |
| | GET|HEAD | admin/employee | employees.index | App\Http\Controllers\Back\EmployeeController#index | web,auth |
| | GET|HEAD | admin/employee/create | employees.create | App\Http\Controllers\Back\EmployeeController#create | web,auth |
| | POST | admin/employee/create | employees.store | App\Http\Controllers\Back\EmployeeController#store | web,auth |
| | GET|HEAD | admin/employee/show/{id} | employees.show | App\Http\Controllers\Back\EmployeeController#show | web,auth |
| | GET|HEAD | admin/employee/{id} | employees.delete | App\Http\Controllers\Back\EmployeeController#destroy | web,auth |
| | PUT | admin/employee/{id} | employees.update | App\Http\Controllers\Back\EmployeeController#update | web,auth |
| | POST | admin/employee/{id}/dossiers/create | create.document.employee.store | App\Http\Controllers\Back\DossierController#dossiers_employees_store | web |
| | GET|HEAD | admin/employee/{id}/dossiers/create | create.document.employee.show | App\Http\Controllers\Back\DossierController#dossiers_employees_create | web |
| | GET|HEAD | admin/employee/{id}/edit | employees.edit | App\Http\Controllers\Back\EmployeeController#edit | web,auth |
| | GET|HEAD | admin/entreprise | entreprises.index | App\Http\Controllers\Back\EntrepriseController#index | web,auth |
| | POST | admin/entreprise/create | entreprises.store | App\Http\Controllers\Back\EntrepriseController#store | web,auth |
| | GET|HEAD | admin/entreprise/create | entreprises.create | App\Http\Controllers\Back\EntrepriseController#create | web,auth |
| | GET|HEAD | admin/entreprise/show/{id} | entreprises.show | App\Http\Controllers\Back\EntrepriseController#show | web,auth |
| | GET|HEAD | api/user | | Closure | api,auth:api |
| | GET|HEAD | home | home | App\Http\Controllers\HomeController#index | web,auth |
| | POST | login | | App\Http\Controllers\Auth\LoginController#login | web,guest |
| | GET|HEAD | login | login | App\Http\Controllers\Auth\LoginController#showLoginForm | web,guest |
| | POST | logout | logout | App\Http\Controllers\Auth\LoginController#logout | web |
| | GET|HEAD | logout | logout | App\Http\Controllers\Auth\LoginController#logout | web |
| | POST | password/email | password.email | App\Http\Controllers\Auth\ForgotPasswordController#sendResetLinkEmail | web,guest |
| | GET|HEAD | password/reset | password.request | App\Http\Controllers\Auth\ForgotPasswordController#showLinkRequestForm | web,guest |
| | POST | password/reset | | App\Http\Controllers\Auth\ResetPasswordController#reset | web,guest |
| | GET|HEAD | password/reset/{token} | password.reset | App\Http\Controllers\Auth\ResetPasswordController#showResetForm | web,guest |
| | GET|HEAD | register | register | App\Http\Controllers\Auth\RegisterController#showRegistrationForm | web,guest |
| | POST | register | | App\Http\Controllers\Auth\RegisterController#register | web,guest |
+--------+----------+-------------------------------------+--------------------------------+------------------------------------------------------------------------+----------------------------------------------+
and php artisan route:clear
i have also tried that :
<form method="POST" action="{{ route('employees.update', $employee_detail->id) }}" aria-label="{{ __('Edit') }}" enctype="multipart/form-data">
#method('PUT')
#csrf
and lets the route designed in web.php unchanged.
it still nothing working.
continu to dispatch to destroy() instead of update().
Someone have an idee ?
Thanks all !
It's because the action you're trying to do and the one you are expecting.
Try this in your route file:
Route::put('/employee/{id}', 'EmployeeController#update')->name('employees.update');
I add a link in case you want to know the difference between "PUT" and "PATCH" HTTP verbs: https://williamdurand.fr/2014/02/14/please-do-not-patch-like-an-idiot/
HTML forms do not support PUT, PATCH or DELETE actions. So, when defining PUT, PATCH or DELETE routes that are called from an HTML form, you will need to add a hidden _method field to the form. The value sent with the _method field will be used as the HTTP request method:
<form action="{{ route('employees.update', $employee_detail->id) }}" method="POST">
<input type="hidden" name="_method" value="PUT">
</form>
You may use the #method Blade directive to generate the _method input:
<form action="{{ route('employees.update', $employee_detail->id) }}" method="POST">
#method('PUT')
</form>
| PUT | admin/employee/{id}/update | employees.update | App\Http\Controllers\Back\EmployeeController#update | web,auth
| GET|HEAD | admin/employee/{id}/delete | employees.delete | App\Http\Controllers\Back\EmployeeController#destroy | web,auth |
i have added update and delete on my route and its worked now....
Route::put('/employee/{id}/update', 'EmployeeController#update')->name('employees.update');
Route::get('/employee/{id}/delete', 'EmployeeController#destroy')->name('employees.delete');
very strange for me...
Related
I am having problems getting some routes to work. I have clearly declared some routes that just don't show up in php artisan route:list, even after clearing the cache.
Since I think this may be related to another line not being correct, I have pasted the entire routes file here. All the admin routes are working, but some "pro" and some "shop" routes are missing completely! There are several missing, so I will not list them all. I am out of thoughts as to how this is happening.
Auth::routes();
Route::prefix('cms')->middleware(['role:admin'])->namespace('Admin')->name('cms.admin.')->group(function () {
Route::get('', 'CmsController#index')->name('index');
Route::get('instellingen', 'CmsController#getSetting')->name('setting.get');
Route::match(['put', 'patch'], 'instellingen', 'CmsController#updateSetting')->name('setting.update');
Route::resource('coaches', 'ProController')->names('pro');
Route::resource('winkels', 'ShopController')->names('shop');
Route::resource('adviezen', 'AdviceController')->names('advice');
Route::resource('notificaties', 'NotificationController')->names('notification');
});
Route::prefix('account')->name('account.')->group(function () {
Route::middleware(['role:shop'])->namespace('Shop')->name('shop.')->group(function () {
Route::get('', 'AccountController#index')->name('index');
Route::get('instellingen', 'AccountController#getSetting')->name('setting.get');
Route::match(['put', 'patch'], 'instellingen', 'AccountController#postSetting')->name('setting.post');
Route::get('profiel', 'AccountController#getProfile')->name('profile.get');
Route::match(['put', 'patch'], 'profiel', 'AccountController#postProfile')->name('profile.post');
Route::get('coaches', 'AccountController#getPro')->name('pro.get');
Route::match(['put', 'patch'], 'coaches', 'AccountController#postPro')->name('pro.post');
Route::resource('adviezen', 'AdviceController')->names('advice');
});
Route::middleware(['role:pro'])->namespace('Pro')->name('pro.')->group(function () {
Route::get('', 'AccountController#index')->name('index');
Route::get('profiel', 'AccountController#getProfile')->name('profile.get');
Route::match(['put', 'patch', 'delete'], 'profiel', 'AccountController#postProfile')->name('profile.post');
Route::get('winkel', 'AccountController#getShop')->name('shop.get');
Route::match(['post', 'delete'], 'winkel', 'AccountController#postShop')->name('shop.post');
Route::get('postvak', 'AccountController#getNotification')->name('notification.get');
Route::post('postvak', 'AccountController#postNotification')->name('notification.post');
Route::resource('adviezen', 'AdviceController')->names('advice');
});
});
Route::get('', 'SiteController#index')->name('site.index');
Result when printing the php artisan route:list -c (Yes, I know this is quite a lot of text, but I think it is necessary to see the complete picture and might help in the solving of this particular problem)
+------------------+------------------------------------+------------------------------------------------------------------------+
| Method | URI | Action |
+------------------+------------------------------------+------------------------------------------------------------------------+
| GET|HEAD | / | App\Http\Controllers\SiteController#index |
| GET|HEAD | _debugbar/assets/javascript | Barryvdh\Debugbar\Controllers\AssetController#js |
| GET|HEAD | _debugbar/assets/stylesheets | Barryvdh\Debugbar\Controllers\AssetController#css |
| DELETE | _debugbar/cache/{key}/{tags?} | Barryvdh\Debugbar\Controllers\CacheController#delete |
| GET|HEAD | _debugbar/clockwork/{id} | Barryvdh\Debugbar\Controllers\OpenHandlerController#clockwork |
| GET|HEAD | _debugbar/open | Barryvdh\Debugbar\Controllers\OpenHandlerController#handle |
| GET|HEAD | _debugbar/telescope/{id} | Barryvdh\Debugbar\Controllers\TelescopeController#show |
| GET|HEAD | account | App\Http\Controllers\Pro\AccountController#index |
| POST | account/adviezen | App\Http\Controllers\Pro\AdviceController#store |
| GET|HEAD | account/adviezen | App\Http\Controllers\Pro\AdviceController#index |
| GET|HEAD | account/adviezen/create | App\Http\Controllers\Pro\AdviceController#create |
| PUT|PATCH | account/adviezen/{adviezen} | App\Http\Controllers\Pro\AdviceController#update |
| GET|HEAD | account/adviezen/{adviezen} | App\Http\Controllers\Pro\AdviceController#show |
| DELETE | account/adviezen/{adviezen} | App\Http\Controllers\Pro\AdviceController#destroy |
| GET|HEAD | account/adviezen/{adviezen}/edit | App\Http\Controllers\Pro\AdviceController#edit |
| PUT|PATCH | account/coaches | App\Http\Controllers\Shop\AccountController#postPro |
| GET|HEAD | account/coaches | App\Http\Controllers\Shop\AccountController#getPro |
| GET|HEAD | account/instellingen | App\Http\Controllers\Shop\AccountController#getSetting |
| PUT|PATCH | account/instellingen | App\Http\Controllers\Shop\AccountController#postSetting |
| GET|HEAD | account/postvak | App\Http\Controllers\Pro\AccountController#getNotification |
| POST | account/postvak | App\Http\Controllers\Pro\AccountController#postNotification |
| PUT|PATCH|DELETE | account/profiel | App\Http\Controllers\Pro\AccountController#postProfile |
| PUT|PATCH | account/profiel | App\Http\Controllers\Shop\AccountController#postProfile |
| GET|HEAD | account/profiel | App\Http\Controllers\Pro\AccountController#getProfile |
| GET|HEAD | account/winkel | App\Http\Controllers\Pro\AccountController#getShop |
| POST|DELETE | account/winkel | App\Http\Controllers\Pro\AccountController#postShop |
| GET|HEAD | api/user | Closure |
| GET|HEAD | cms | App\Http\Controllers\Admin\CmsController#index |
| GET|HEAD | cms/adviezen | App\Http\Controllers\Admin\AdviceController#index |
| POST | cms/adviezen | App\Http\Controllers\Admin\AdviceController#store |
| GET|HEAD | cms/adviezen/create | App\Http\Controllers\Admin\AdviceController#create |
| PUT|PATCH | cms/adviezen/{adviezen} | App\Http\Controllers\Admin\AdviceController#update |
| DELETE | cms/adviezen/{adviezen} | App\Http\Controllers\Admin\AdviceController#destroy |
| GET|HEAD | cms/adviezen/{adviezen} | App\Http\Controllers\Admin\AdviceController#show |
| GET|HEAD | cms/adviezen/{adviezen}/edit | App\Http\Controllers\Admin\AdviceController#edit |
| GET|HEAD | cms/coaches | App\Http\Controllers\Admin\ProController#index |
| POST | cms/coaches | App\Http\Controllers\Admin\ProController#store |
| GET|HEAD | cms/coaches/create | App\Http\Controllers\Admin\ProController#create |
| GET|HEAD | cms/coaches/{coach} | App\Http\Controllers\Admin\ProController#show |
| DELETE | cms/coaches/{coach} | App\Http\Controllers\Admin\ProController#destroy |
| PUT|PATCH | cms/coaches/{coach} | App\Http\Controllers\Admin\ProController#update |
| GET|HEAD | cms/coaches/{coach}/edit | App\Http\Controllers\Admin\ProController#edit |
| PUT|PATCH | cms/instellingen | App\Http\Controllers\Admin\CmsController#updateSetting |
| GET|HEAD | cms/instellingen | App\Http\Controllers\Admin\CmsController#getSetting |
| GET|HEAD | cms/notificaties | App\Http\Controllers\Admin\NotificationController#index |
| POST | cms/notificaties | App\Http\Controllers\Admin\NotificationController#store |
| GET|HEAD | cms/notificaties/create | App\Http\Controllers\Admin\NotificationController#create |
| GET|HEAD | cms/notificaties/{notificaty} | App\Http\Controllers\Admin\NotificationController#show |
| PUT|PATCH | cms/notificaties/{notificaty} | App\Http\Controllers\Admin\NotificationController#update |
| DELETE | cms/notificaties/{notificaty} | App\Http\Controllers\Admin\NotificationController#destroy |
| GET|HEAD | cms/notificaties/{notificaty}/edit | App\Http\Controllers\Admin\NotificationController#edit |
| POST | cms/winkels | App\Http\Controllers\Admin\ShopController#store |
| GET|HEAD | cms/winkels | App\Http\Controllers\Admin\ShopController#index |
| GET|HEAD | cms/winkels/create | App\Http\Controllers\Admin\ShopController#create |
| GET|HEAD | cms/winkels/{winkel} | App\Http\Controllers\Admin\ShopController#show |
| DELETE | cms/winkels/{winkel} | App\Http\Controllers\Admin\ShopController#destroy |
| PUT|PATCH | cms/winkels/{winkel} | App\Http\Controllers\Admin\ShopController#update |
| GET|HEAD | cms/winkels/{winkel}/edit | App\Http\Controllers\Admin\ShopController#edit |
| GET|HEAD | login | App\Http\Controllers\Auth\LoginController#showLoginForm |
| POST | login | App\Http\Controllers\Auth\LoginController#login |
| POST | logout | App\Http\Controllers\Auth\LoginController#logout |
| POST | password/confirm | App\Http\Controllers\Auth\ConfirmPasswordController#confirm |
| GET|HEAD | password/confirm | App\Http\Controllers\Auth\ConfirmPasswordController#showConfirmForm |
| POST | password/email | App\Http\Controllers\Auth\ForgotPasswordController#sendResetLinkEmail |
| GET|HEAD | password/reset | App\Http\Controllers\Auth\ForgotPasswordController#showLinkRequestForm |
| POST | password/reset | App\Http\Controllers\Auth\ResetPasswordController#reset |
| GET|HEAD | password/reset/{token} | App\Http\Controllers\Auth\ResetPasswordController#showResetForm |
| POST | register | App\Http\Controllers\Auth\RegisterController#register |
| GET|HEAD | register | App\Http\Controllers\Auth\RegisterController#showRegistrationForm |
+------------------+------------------------------------+------------------------------------------------------------------------+
It is not a syntax error, since my IDE does not give an error, so I am thinking it might be a logical one or something I am completely missing...
Any help would be much appreciated.
Kind regards,
Niels
Although the result was pretty embarrassing;
What I did was register multiple routes with the same URI and method. Although they had different namespaces and names, it conflicted.
Fixed by prefixing the URI in the 2 separate groups
Thanks to user lagbox for the answer.
I have a very simple form:
{!! Form::open(['route' => ['complete.order']]) !!}
{!! Form::hidden('date', \Carbon\Carbon::now()->format('F j, Y ')) !!}
{!! Form::hidden('web_token', $order->web_token) !!}
{!! Form::submit('Place this order', ['class'=>'btn btn-primary']) !!}
{!! Form::close() !!}
When I visit the page, this renders as follows:
<form method="POST" action="http://site.localhost/place-order" accept-charset="UTF-8">
<input name="_token" type="hidden" value="kc6d4XoZ78RvJNtQbN8lavpLP7e1lI7rTGBvbeIP">
<input name="date" type="hidden" value="December 21, 2018 ">
<input name="id" type="hidden" value="15">
<input class="btn btn-primary" type="submit" value="Place this order">
</form>
Here are the relevant routes:
Route::get('/orders/form', 'OrdersController#viewform')->name('orderform');
Route::post('/orders/review', 'OrdersController#review')->name('orders.review');
Route::post('/place-order', 'OrdersController#store')->name('complete.order');
Route::resource('/orders', 'OrdersController', ['except'=>['edit', 'update', 'destroy', 'show', 'store']])->middleware('auth');
Route::get('/orders/{order}', 'OrdersController#show')->name('orders.show');
When I click on the submit button, I'm directed to site.localhost/orders/review, which according to the debug bar is being passed to as a GET request, not POST.
I can't figure out why this is happening. The form should be going to site.localhost/place-order, which currently just outputs return('place') for testing.
The code in OrdersController#show currently outputs return('show'). I've done the same across all of the OrdersController methods for testing.
Adding php artisan route output
+--------+-----------+-------------------------------+-----------------------+------------------------------------------------------------------------+------------------------------------------------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+-----------+-------------------------------+-----------------------+------------------------------------------------------------------------+------------------------------------------------------+
| | GET|HEAD | / | | App\Http\Controllers\HomeController#index | web,auth |
| | GET|HEAD | _debugbar/assets/javascript | debugbar.assets.js | Barryvdh\Debugbar\Controllers\AssetController#js | Barryvdh\Debugbar\Middleware\DebugbarEnabled,Closure |
| | GET|HEAD | _debugbar/assets/stylesheets | debugbar.assets.css | Barryvdh\Debugbar\Controllers\AssetController#css | Barryvdh\Debugbar\Middleware\DebugbarEnabled,Closure |
| | DELETE | _debugbar/cache/{key}/{tags?} | debugbar.cache.delete | Barryvdh\Debugbar\Controllers\CacheController#delete | Barryvdh\Debugbar\Middleware\DebugbarEnabled,Closure |
| | GET|HEAD | _debugbar/clockwork/{id} | debugbar.clockwork | Barryvdh\Debugbar\Controllers\OpenHandlerController#clockwork | Barryvdh\Debugbar\Middleware\DebugbarEnabled,Closure |
| | GET|HEAD | _debugbar/open | debugbar.openhandler | Barryvdh\Debugbar\Controllers\OpenHandlerController#handle | Barryvdh\Debugbar\Middleware\DebugbarEnabled,Closure |
| | GET|HEAD | api/user | | Closure | api,auth:api |
| | GET|HEAD | confirm-account/{token} | | App\Http\Controllers\UserController#create | web |
| | GET|HEAD | home | home | App\Http\Controllers\HomeController#index | web,auth |
| | GET|HEAD | login | login | App\Http\Controllers\Auth\LoginController#showLoginForm | web,guest |
| | POST | login | | App\Http\Controllers\Auth\LoginController#login | web,guest |
| | POST | logout | logout | App\Http\Controllers\Auth\LoginController#logout | web |
| | GET|HEAD | my-account | my-account.index | App\Http\Controllers\UserController#index | web,auth |
| | POST | my-account | my-account.store | App\Http\Controllers\UserController#store | web,auth |
| | GET|HEAD | my-account/create | my-account.create | App\Http\Controllers\UserController#create | web,auth |
| | PUT|PATCH | my-account/{my_account} | my-account.update | App\Http\Controllers\UserController#update | web,auth |
| | DELETE | my-account/{my_account} | my-account.destroy | App\Http\Controllers\UserController#destroy | web,auth |
| | GET|HEAD | my-account/{my_account} | my-account.show | App\Http\Controllers\UserController#show | web,auth |
| | GET|HEAD | my-account/{my_account}/edit | my-account.edit | App\Http\Controllers\UserController#edit | web,auth |
| | POST | orders | orders.store | App\Http\Controllers\OrdersController#store | web,auth |
| | GET|HEAD | orders | orders.index | App\Http\Controllers\OrdersController#index | web,auth |
| | GET|HEAD | orders/create | orders.create | App\Http\Controllers\OrdersController#create | web,auth |
| | GET|HEAD | orders/form | orderform | App\Http\Controllers\OrdersController#viewform | web |
| | POST | orders/review | orders.review | App\Http\Controllers\OrdersController#review | web |
| | GET|HEAD | orders/{order} | orders.show | App\Http\Controllers\OrdersController#show | web |
| | POST | password/email | password.email | App\Http\Controllers\Auth\ForgotPasswordController#sendResetLinkEmail | web,guest |
| | POST | password/reset | | App\Http\Controllers\Auth\ResetPasswordController#reset | web,guest |
| | GET|HEAD | password/reset | password.request | App\Http\Controllers\Auth\ForgotPasswordController#showLinkRequestForm | web,guest |
| | GET|HEAD | password/reset/{token} | password.reset | App\Http\Controllers\Auth\ResetPasswordController#showResetForm | web,guest |
| | POST | place-order | complete.order | App\Http\Controllers\OrdersController#store | web |
| | POST | register | | App\Http\Controllers\Auth\RegisterController#register | web,guest |
| | GET|HEAD | register | register | App\Http\Controllers\Auth\RegisterController#showRegistrationForm | web,guest |
| | POST | user/store | user.store | App\Http\Controllers\UserController#store | web |
+--------+-----------+-------------------------------+-----------------------+------------------------------------------------------------------------+------------------------------------------------------+
Okay, I'm a complete and utter idiot.
The problem was that I was using a custom request for validation, which this route didn't meet. So it was actually returning the page back with errors, but since I didn't realize this it wasn't showing any errors.
Your problem is generated because you are using Route::resource, this route defines, index, create, store, show, edit, update and destroy routes for your controller and you're trying to overwrite the store route:
Route::post('/place-order', 'OrdersController#store')->name('complete.order');
You can use change your form code like this:
{!! Form::open(['route' => ['orders.store']]) !!}
Or you can create a new function in your controller:
public function newfucntion(Request $request)
{
//All your code here
}
Then create the new route:
Route::post('/place-order', 'OrdersController#newFunction')->name('complete.order');
And then change your form like this:
{!! Form::open(['route' => ['complete.order']]) !!}
you know, Laravel Passport have predefined routes as folllow:
php artisan route:list
+--------+----------+-----------------------------------------+------+---------------------------------------------+--------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+-----------------------------------------+------+---------------------------------------------+--------------+
| | GET|HEAD | / | | Closure | web |
| | POST | oauth/authorize | | ...\ApproveAuthorizationController#approve | web,auth |
| | GET|HEAD | oauth/authorize | | ...\AuthorizationController#authorize | web,auth |
| | DELETE | oauth/authorize | | ...\DenyAuthorizationController#deny | web,auth |
| | GET|HEAD | oauth/clients | | ...\ClientController#forUser | web,auth |
| | POST | oauth/clients | | ...\ClientController#store | web,auth |
| | PUT | oauth/clients/{client_id} | | ...\ClientController#update | web,auth |
| | DELETE | oauth/clients/{client_id} | | ...\ClientController#destroy | web,auth |
| | GET|HEAD | oauth/personal-access-tokens | | ...\PersonalAccessTokenController#forUser | web,auth |
| | POST | oauth/personal-access-tokens | | ...\PersonalAccessTokenController#store | web,auth |
| | DELETE | oauth/personal-access-tokens/{token_id} | | ...\PersonalAccessTokenController#destroy | web,auth |
| | GET|HEAD | oauth/scopes | | ...\ScopeController#all | web,auth |
| | POST | oauth/token | | ...\AccessTokenController#issueToken | throttle |
| | POST | oauth/token/refresh | | ...\TransientTokenController#refresh | web,auth |
| | GET|HEAD | oauth/tokens | | ...\AuthorizedAccessTokenController#forUser | web,auth |
| | DELETE | oauth/tokens/{token_id} | | ...\AuthorizedAccessTokenController#destroy | web,auth |
+--------+----------+-----------------------------------------+------+---------------------------------------------+--------------+
Is it possible to modify that route?
e.g. oauth/authorize become api/v1/oauth/authorize
if yes, how?
I've been searching for answer quite sometime...
Yes, it is. You can declare your own routes in Passport::routes() method.
Include this inside the boot() method of your app/Providers/AuthServiceProvider file.
app/Providers/AuthServiceProvider.php
public function boot()
{
Passport::routes(null, ['prefix' => 'api/v1/oauth']);
}
It seems like the routes method has been removed (Passport 11.x).
In order to do this now, you would need to publish the Passport configuration file and set the path attribute to the desired value: api/v1/oauth.
php artisan vendor:publish --tag=passport-config
// config/passport.php
<?php
return [
...
'path' => 'api/v1/oauth',
];
I haven't been able to find this information in the documentation. I figured this out by looking at the source code. Here's the link for further reference.
I'm trying to submit data to my Laravel Controller using Ajax, but I'm getting the error "422 (Unprocessable Entity)".
I've done some Googling, and I think it is to do with the JSON being passed, but I'm unsure how to solve it.
The following is what I believe to be the relevant info:
Script
$("#addStepNew").click(function() {
var step_ingredients = JSON.stringify(stepIngredients)
var step_description = $('#stepDescription').val();
var prep_step = $('input[name=prepStep]:checked').val();
$.ajax({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
type: "post",
data: "ingredients="+step_ingredients+"&description="+step_description+"&is_prep="+prep_step+"step_no=1",
dataType:'json',
url: "{{ route('ingredients.store', ['id' => $recipe->id]) }}",
success:function(data){
console.log(data);
$("#output").html('<div class="alert alert-success my-0">'+data.name+' added</div>');
$("#output").toggleClass("invisible")
$("#output").fadeOut(2000);
}
});
});
The console.log(stepIngredients) gives [{"ingredient_id":"9","ingredient_quantity":"3","Ingredient_units":"kilograms"}]
The idea is to pass it all through to my controller, and write the values to the DB, but at the minute I can't even pass the info.
I've done the following to my controller:
public function store(Request $request)
{
//$this->validate($request);
/*
$step = new Step;
$step->recipe_id = $request->recipe_id;
$step->step_no = $request->step_no;
$step->method = $request->description;
$step->save();
*/
$data = [
'success' => true,
'message'=> 'Your AJAX processed correctly',
] ;
return response()->json($data);
}
So as I understand it (I'm teaching myself this as I go along), if the AJAX is passed successfully, then it should return the success message and output it in my #output div?
+--------+-----------+--------------------------+--------------------+------------------------------------------------------------------------+--------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+-----------+--------------------------+--------------------+------------------------------------------------------------------------+--------------+
| | GET|HEAD | / | | App\Http\Controllers\PagesController#index | web |
| | GET|HEAD | api/user | | Closure | api,auth:api |
| | GET|HEAD | home | home | App\Http\Controllers\HomeController#index | web,auth |
| | GET|HEAD | login | login | App\Http\Controllers\Auth\LoginController#showLoginForm | web,guest |
| | POST | login | | App\Http\Controllers\Auth\LoginController#login | web,guest |
| | POST | logout | logout | App\Http\Controllers\Auth\LoginController#logout | web |
| | POST | password/email | password.email | App\Http\Controllers\Auth\ForgotPasswordController#sendResetLinkEmail | web,guest |
| | GET|HEAD | password/reset | password.request | App\Http\Controllers\Auth\ForgotPasswordController#showLinkRequestForm | web,guest |
| | POST | password/reset | | App\Http\Controllers\Auth\ResetPasswordController#reset | web,guest |
| | GET|HEAD | password/reset/{token} | password.reset | App\Http\Controllers\Auth\ResetPasswordController#showResetForm | web,guest |
| | GET|HEAD | recipes | recipes.index | App\Http\Controllers\RecipesController#index | web,auth |
| | POST | recipes | recipes.store | App\Http\Controllers\RecipesController#store | web,auth |
| | GET|HEAD | recipes/create | recipes.create | App\Http\Controllers\RecipesController#create | web,auth |
| | GET|HEAD | recipes/{id}/ingredients | ingredients.create | App\Http\Controllers\IngredientsController#create | web,auth |
| | POST | recipes/{id}/ingredients | ingredients.store | App\Http\Controllers\IngredientsController#store | web,auth |
| | GET|HEAD | recipes/{id}/steps | steps.create | App\Http\Controllers\StepsController#create | web,auth |
| | POST | recipes/{id}/steps | steps.store | App\Http\Controllers\StepsController#store | web,auth |
| | PUT|PATCH | recipes/{recipe} | recipes.update | App\Http\Controllers\RecipesController#update | web,auth |
| | DELETE | recipes/{recipe} | recipes.destroy | App\Http\Controllers\RecipesController#destroy | web,auth |
| | GET|HEAD | recipes/{recipe} | recipes.show | App\Http\Controllers\RecipesController#show | web,auth |
| | GET|HEAD | recipes/{recipe}/edit | recipes.edit | App\Http\Controllers\RecipesController#edit | web,auth |
| | POST | register | | App\Http\Controllers\Auth\RegisterController#register | web,guest |
| | GET|HEAD | register | register | App\Http\Controllers\Auth\RegisterController#showRegistrationForm | web,guest |
| | GET|HEAD | tags | tags.index | App\Http\Controllers\TagsController#index | web,auth |
| | POST | tags | tags.store | App\Http\Controllers\TagsController#store | web,auth |
| | GET|HEAD | tags/create | tags.create | App\Http\Controllers\TagsController#create | web,auth |
| | GET|HEAD | tags/{tag} | tags.show | App\Http\Controllers\TagsController#show | web,auth |
| | PUT|PATCH | tags/{tag} | tags.update | App\Http\Controllers\TagsController#update | web,auth |
| | DELETE | tags/{tag} | tags.destroy | App\Http\Controllers\TagsController#destroy | web,auth |
| | GET|HEAD | tags/{tag}/edit | tags.edit | App\Http\Controllers\TagsController#edit | web,auth |
+--------+-----------+--------------------------+--------------------+------------------------------------------------------------------------+--------------+
I'm using Laravel Framework version 5.4.36 and i have setup success passport,i have run command
php artisan vendor:publish --tag=passport-components
My routes:
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+-----------------------------------------+------------+----------------------------------------------------------------------------+--------------+
| | GET|HEAD | / | | Closure | web |
| | POST | api/details | | App\Http\Controllers\API\UserController#details | api,auth:api |
| | POST | api/login | | App\Http\Controllers\API\UserController#login | api |
| | GET|HEAD | api/loginError | loginError | App\Http\Controllers\API\UserController#loginError | api |
| | POST | api/register | | App\Http\Controllers\API\UserController#register | api |
| | GET|HEAD | api/test | test | App\Http\Controllers\API\UserController#test | api,auth:api |
| | GET|HEAD | api/user | | Closure | api,auth:api |
| | GET|HEAD | home | home | App\Http\Controllers\HomeController#index | web,auth |
| | GET|HEAD | oauth/authorize | | \Laravel\Passport\Http\Controllers\AuthorizationController#authorize | web,auth |
| | POST | oauth/authorize | | \Laravel\Passport\Http\Controllers\ApproveAuthorizationController#approve | web,auth |
| | DELETE | oauth/authorize | | \Laravel\Passport\Http\Controllers\DenyAuthorizationController#deny | web,auth |
| | POST | oauth/clients | | \Laravel\Passport\Http\Controllers\ClientController#store | web,auth |
| | GET|HEAD | oauth/clients | | \Laravel\Passport\Http\Controllers\ClientController#forUser | web,auth |
| | PUT | oauth/clients/{client_id} | | \Laravel\Passport\Http\Controllers\ClientController#update | web,auth |
| | DELETE | oauth/clients/{client_id} | | \Laravel\Passport\Http\Controllers\ClientController#destroy | web,auth |
| | GET|HEAD | oauth/personal-access-tokens | | \Laravel\Passport\Http\Controllers\PersonalAccessTokenController#forUser | web,auth |
| | POST | oauth/personal-access-tokens | | \Laravel\Passport\Http\Controllers\PersonalAccessTokenController#store | web,auth |
| | DELETE | oauth/personal-access-tokens/{token_id} | | \Laravel\Passport\Http\Controllers\PersonalAccessTokenController#destroy | web,auth |
| | GET|HEAD | oauth/scopes | | \Laravel\Passport\Http\Controllers\ScopeController#all | web,auth |
| | POST | oauth/token | | \Laravel\Passport\Http\Controllers\AccessTokenController#issueToken | throttle |
| | POST | oauth/token/refresh | | \Laravel\Passport\Http\Controllers\TransientTokenController#refresh | web,auth |
| | GET|HEAD | oauth/tokens | | \Laravel\Passport\Http\Controllers\AuthorizedAccessTokenController#forUser | web,auth |
| | DELETE | oauth/tokens/{token_id} | | \Laravel\Passport\Http\Controllers\AuthorizedAccessTokenController#destroy | web,auth |
| | GET|HEAD | testOracle | testOracle | App\Http\Controllers\WellcomeController#testOracle | web |
I cannot found get uri oauth/clients,it is in action \Laravel\Passport\Http\Controllers\ClientController#forUser,
My error is cannot found action \Laravel\Passport\Http\Controllers\ClientController#forUser,
when i have go to folder vendor,i only see vendor\laravel\passport
passport folder
it is not have link \Laravel\Passport\Http`
How can i fix this error,thank you
Go to \vendor\laravel\passport\src folder. You will find Http folder there.