Overriding rydurham/sentinel route paths in Laravel 5 - php

I am using the rydurhmam/sentinel package in Laravel 5.0.x and I cannot change how the default mysite.com/profile route is handled.
In my routes.php file I have declared Route::resource('profile', 'ProfileController');
When I call php artisan route:list I get:
| GET|HEAD | profile | sentinel.profile.show | Sentinel\Controllers\ProfileController#show | sentry.auth |
| GET|HEAD | profile/create | profile.create | App\Http\Controllers\ProfileController#create | sentry.auth |
| POST | profile | profile.store | App\Http\Controllers\ProfileController#store | sentry.auth |
| GET|HEAD | profile/{profile} | profile.show | App\Http\Controllers\ProfileController#show | sentry.auth |
| GET|HEAD | profile/{profile}/edit | profile.edit | App\Http\Controllers\ProfileController#edit | sentry.auth |
| PUT | profile/{profile} | profile.update | App\Http\Controllers\ProfileController#update | sentry.auth |
| PATCH | profile/{profile} | | App\Http\Controllers\ProfileController#update | sentry.auth |
| DELETE | profile/{profile} | profile.destroy | App\Http\Controllers\ProfileController#destroy | sentry.auth |
And you'll notice the first profile route is handled by the Sentinel Controller found within the vendor package file.
The sentinel config file only allows you to turn off routing in its entirety, so is there anyway to override selected controllers or am I SOL?

Try this:
In config/sentinel.php
'routes_enabled' => false,
in your routes.php
include(dirname(with(new ReflectionClass('Sentinel\SentinelServiceProvider'))->getFileName()) . '/../routes.php');
and declare your routes as normal in routes.php file after include
and that should work fine.
let me know.

Related

routes names for a resource not shown properly in laravel 5.7

using laravel 5.7, i have the following code line in routes/web.php
Route::resource('admin/users', 'Admin\AdminUsersController');
when i list routes via : php artisan route:list i get the following:
| | GET|HEAD | admin/users | users.index | App\Http\Controllers\Admin\AdminUsersController#index | web
| | POST | admin/users | users.store | App\Http\Controllers\Admin\AdminUsersController#store | web
| | GET|HEAD | admin/users/create | users.create | App\Http\Controllers\Admin\AdminUsersController#create | web
| | GET|HEAD | admin/users/{user} | users.show | App\Http\Controllers\Admin\AdminUsersController#show | web
| | PUT|PATCH | admin/users/{user} | users.update | App\Http\Controllers\Admin\AdminUsersController#update | web
| | DELETE | admin/users/{user} | users.destroy | App\Http\Controllers\Admin\AdminUsersController#destroy | web
| | GET|HEAD | admin/users/{user}/edit | users.edit | App\Http\Controllers\Admin\AdminUsersController#edit | web
why routes are not named following the directory structure : admin.users.method
Laravel takes the last string after slash in resource routes to decide the route name. You can refer Illuminate/Routing/ResourceRegistrar.php file's register() and prefixedResource() methods.

Laravel missing routes issue

i have a problem with my Laravel routes.
if i call the following url: http://laravel/market it works fine, but my site has different languages so i use the LaravelLocalization package and when i call http://laravel/en/market it comes an error:
Route [market.offers.show] not defined.
i have used:
php artisan route:list
to see the indexed routes and here is a shortcut of it:
| GET|HEAD | market/offers | market.offers.index | App\Http\Controllers\Front\OffersController#index
| POST | market/offers | market.offers.store | App\Http\Controllers\Front\OffersController#store
| GET|HEAD | market/offers/bid/{id} | market.offers.bid | App\Http\Controllers\Front\OffersController#bid
| GET|HEAD | market/offers/create | market.offers.create | App\Http\Controllers\Front\OffersController#create
| GET|HEAD | market/offers/history | market.offers.history | App\Http\Controllers\Front\OffersController#history
| POST | market/offers/store/bid | market.offers.store.bid | App\Http\Controllers\Front\OffersController#storebid
| DELETE | market/offers/{offers} | market.offers.destroy | App\Http\Controllers\Front\OffersController#destroy
| GET|HEAD | market/offers/{offers} | market.offers.show | App\Http\Controllers\Front\OffersController#show
| PUT|PATCH | market/offers/{offers} | market.offers.update | App\Http\Controllers\Front\OffersController#update
| GET|HEAD | market/offers/{offers}/edit | market.offers.edit | App\Http\Controllers\Front\OffersController#edit
on other pages i get the same error for Route [market.offers.create]
why is that ? How can i resolve that ?
in your routes you should add a wildcard for the language for example it will look like /laravel/{lang}/market
and then in your controllers you handle the if the lang is null or not to set the default language

Laravel5 make:auth doesn't work

I used the command make:auth and it showed:
Created View: /var/www/myblog/resources/views/auth/login.blade.php
Created View: /var/www/myblog/resources/views/auth/register.blade.php
Created View: /var/www/myblog/resources/views/auth/passwords/email.blade.php
Created View: /var/www/myblog/resources/views/auth/passwords/reset.blade.php
Created View: /var/www/myblog/resources/views/auth/emails/password.blade.php
Created View: /var/www/myblog/resources/views/layouts/app.blade.php
Created View: /var/www/myblog/resources/views/home.blade.php
Created View: /var/www/myblog/resources/views/welcome.blade.php
Installed HomeController.
Updated Routes File.
Authentication scaffolding generated successfully!
It looks like great and I got a homepage showing up correctly.
see picture here
But when I was trying to access Login and Register page, something went wrong.
It gave me errors like:
Not Found
The requested URL /login was not found on this server.
Apache/2.4.7 (Ubuntu) Server at ...
and I typed php artisan route:list in terminal I got this:
+--------+-----------+-------------------------+-----------------+-----------------------------------------------------------------+------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+-----------+-------------------------+-----------------+-----------------------------------------------------------------+------------+
| | GET|HEAD | / | | Closure | |
| | GET|HEAD | article | article.index | App\Http\Controllers\ArticleController#index | |
| | POST | article | article.store | App\Http\Controllers\ArticleController#store | |
| | GET|HEAD | article/create | article.create | App\Http\Controllers\ArticleController#create | |
| | DELETE | article/{article} | article.destroy | App\Http\Controllers\ArticleController#destroy | |
| | PUT|PATCH | article/{article} | article.update | App\Http\Controllers\ArticleController#update | |
| | GET|HEAD | article/{article} | article.show | App\Http\Controllers\ArticleController#show | |
| | GET|HEAD | article/{article}/edit | article.edit | App\Http\Controllers\ArticleController#edit | |
| | GET|HEAD | home | | App\Http\Controllers\HomeController#index | web,auth |
| | GET|HEAD | login | | App\Http\Controllers\Auth\AuthController#showLoginForm | web,guest |
| | POST | login | | App\Http\Controllers\Auth\AuthController#login | web,guest |
| | GET|HEAD | logout | | App\Http\Controllers\Auth\AuthController#logout | web |
| | POST | password/email | | App\Http\Controllers\Auth\PasswordController#sendResetLinkEmail | web,guest |
| | POST | password/reset | | App\Http\Controllers\Auth\PasswordController#reset | web,guest |
| | GET|HEAD | password/reset/{token?} | | App\Http\Controllers\Auth\PasswordController#showResetForm | web,guest |
| | GET|HEAD | register | | App\Http\Controllers\Auth\AuthController#showRegistrationForm | web,guest |
| | POST | register | | App\Http\Controllers\Auth\AuthController#register | web,guest |
+--------+-----------+-------------------------+-----------------+-----------------------------------------------------------------+------------+
It's a bit different from what I expect. Cuz from what I learned in laracast.com, the route list should be like "Auth\login" instead of merely "login"... Idk what's going wrong here, is it because I'm using apache? or other configurations I didn't set up correctly... Looking for help
Also another question:
when I access www.mydomain.com, I'd expect the default welcome page instead of auth's home page but actually it gives me the auth's home page instead. But when I was trying to access www.mydomain.com/home which I expect to see that home page again, instead I received 404 not found errors which confused me a lot. here is my routes.php:
<?php
/*
|--------------------------------------------------------------------------
| Routes File
|--------------------------------------------------------------------------
|
| Here is where you will register all of the routes in an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::get('/', function () {
return view('welcome');
});
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| This route group applies the "web" middleware group to every route
| it contains. The "web" middleware group is defined in your HTTP
| kernel and includes session state, CSRF protection, and more.
|
*/
Route::resource('article', 'ArticleController');
Route::group(['middleware' => 'web'], function () {
Route::auth();
Route::get('/home', 'HomeController#index');
});
Hi Guys I just solved this problem.
This problem is definitely unrelated to laravel and is totally caused by Apache2 settings.
What I did is simply
sudo a2enmod rewrite
and restart service.

Change default RESTFul actions laravel

I created a controller named CatController with php artisan make:controller CatController. So it generated the next route list:*-> What generated the route list is on routes.php Route::resource('cat','CatsController');
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+-------------------+-------------+-------------------------------------------------+------------+
| | GET|HEAD | / | | Furbook\Http\Controllers\CatController#index | |
| | GET|HEAD | cat | cat.index | Furbook\Http\Controllers\CatController#index | |
| | POST | cat | cat.store | Furbook\Http\Controllers\CatController#store | |
| | GET|HEAD | cat/create | cat.create | Furbook\Http\Controllers\CatController#create | |
| | DELETE | cat/{cat} | cat.destroy | Furbook\Http\Controllers\CatController#destroy | |
| | PATCH | cat/{cat} | | Furbook\Http\Controllers\CatController#update | |
| | PUT | cat/{cat} | cat.update | Furbook\Http\Controllers\CatController#update | |
| | GET|HEAD | cat/{cat} | cat.show | Furbook\Http\Controllers\CatController#show | |
| | GET|HEAD | cat/{cat}/edit | cat.edit | Furbook\Http\Controllers\CatController#edit | |
Later on I thought it would be better to call it CatsController and handle the urls as cats/... so I renamed the controller but I still have the same default REST actions URIs.
Is there anyway to change it? How should I proceed?
To my knowledge the make:controller command only generates the controller file, not any route definitions. The routes defined there look like they've beed generated by a Route::resource definition that would look like this:
Route::resource('cat', 'CatController');
To make that work with cats and CatsControllers you should change it to this:
Route::resource('cats', 'CatsController');
You can read more on RESTful Resource Controllers in the Laravel Documentation.

Route does not exist when redirecting to resource route [Laravel]

I have the following Route defined:
Route::resource('profile', 'ProfileController', ['except' => ['create', 'destroy']]);
However, when I try and redirect to the profile/{id} method using the following:
redirect()->route('profile', [$userId]);
I get the following error:
InvalidArgumentException in UrlGenerator.php line 278:
Route [profile] not defined.
What could be the issue?
The route method takes a route name as the first argument. All specific resource routes will get their own names, however there's none created with the name of the base resource (profile).
By running php artisan route:list you will see a list of all routes along with their names. For you it should look something like this:
+--------+----------+-----------------------------------------+-----------------+---------------------------------------------------+------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+-----------------------------------------+-----------------+---------------------------------------------------+------------+
| | POST | profile | profile.store | App\Http\Controllers\ProfileController#store | |
| | GET|HEAD | profile | profile.index | App\Http\Controllers\ProfileController#index | |
| | GET|HEAD | profile/create | profile.create | App\Http\Controllers\ProfileController#create | |
| | PATCH | profile/{profile} | | App\Http\Controllers\ProfileController#update | |
| | PUT | profile/{profile} | profile.update | App\Http\Controllers\ProfileController#update | |
| | DELETE | profile/{profile} | profile.destroy | App\Http\Controllers\ProfileController#destroy | |
| | GET|HEAD | profile/{profile} | profile.show | App\Http\Controllers\ProfileController#show | |
| | GET|HEAD | profile/{profile}/edit | profile.edit | App\Http\Controllers\ProfileController#edit | |
+--------+----------+-----------------------------------------+-----------------+---------------------------------------------------+------------+
So since it seems you are intending to show a user profile, this should be what you are looking to do:
redirect()->route('profile.show', [$userId]);
Try redirect this way
return redirect('profile/2');

Categories