I'm trying to add a new page in laravel. I've checked the index page, controller and I keep getting a 404 error.
web.php
Route::group(
['namespace' => 'Admin', 'prefix' => 'admin', 'as' => 'admin.', 'middleware' => ['role:admin']],
function () {
Route::group(
['middleware' => ['licence-expire']],
function () {
Route::resource('curriculum', 'AdminCurriculumController');
Controller
public function index()
{
$this->curriculum =Curriculum::count();
return view('admin.curriculum.index', $this->data);
}
By using prefix all routes in the group get the admin/ prefix. The curriculum resource can then be found at localhost/admin/curriculum/. You can list all available routes by issuing php artisan route:list
If the route doesn't show up in php artisan route:list try clearing the cache: php artisan route:clear. If this doesn't work try adding a test url to ensure the cache is cleared:
Route::get('/', function () {
return view('welcome');
});
Try
php artisan cache:clear
You have probably cached your routes, so you can't add any more because Laravel will now be based on the cached file and not on the web.php file you are updating
Related
config: laravel 5.5
web.php
Route::group([
// 'middleware' => ['auth', 'is_admin'],
'namespace' => 'Admin',
'prefix' => 'admin',
],
function () {
Route::get('/', function(){
return 'admin';
});
Route::get('/pages', 'AdminController#pages')->name('admin_pages');
});
php artisan route:list
http://prntscr.com/moltmg
but get http://prntscr.com/moluky empty page
I don’t know what the problem is, I’m registering the path, I’ll use group, but I’m getting a blank page, no error, nothing. Other path work fine, also if I register a path in a group, for example:
admin / dashboard
everything is fine, only this one does not work.
Try running these commands.
php artisan config:clear
php artisan cache:clear
composer dump-autoload -o
if still not working.
provide 777 permission to storage and bootstrap/cache folders.
you need to add the route::get in your group.
this is an example that can help you :
Route::group(['prefix' => 'admin', 'middleware' => 'auth'], function()
{
//All the routes that you have :
Route::get('/pages', 'AdminController#pages')->name('admin_pages');
});
Hope this helps :) good luck
I apologize for the disturb, I am an idiot and created the "admin" folder in the "public" folder.
I have just downloaded Laravel 5.7.2 project and found an issue below.
Below line does not work in Laravel 5.7.2 and gives 404
Route::get('/login',
array(
'uses' => 'Annonymous\Web\Auth\Login\LoginController#showLoginForm',
'as' => 'showLoginForm'
)
);
Below works in Laravel 5.7.2
Route::get('/', function () {
return view('Annonymous.welcome');
});
Below code works in Laravel 5.6.16 and 5.6.33
Route::get('/login',
array(
'uses' => 'Annonymous\Web\Auth\Login\LoginController#showLoginForm',
'as' => 'showLoginForm'
)
);
Any idea why the same code does not work in 5.7.2 ?
I can confirm that the route is present in the route list.
Since your project is not in root of Localhost
Try 'php artisan serve'
It Will Work
I made the files for authentication using the command
php artisan make:auth
I've read on the internet that register, login, as well as logout should work properly, but localhost:8080/logout doesn't work, and I don't know why.
I also read something about modifying AuthController in app, but I do not have that file.
I tried to do it by hand, which means I created a middleware LogoutRedirect:
public function handle($request, Closure $next)
{
return redirect(pages.logout);
}
In the routes I added
use App\Http\Middleware\LogoutRedirect;
Route::get('logout', function()
{
return view('pages.logout');
})->middleware(LogoutRedirect::class);
And logout.blade.php looks like
{{ Auth::logout() }}
I get the error (when trying to access localhost:8080/logout)
Use of undefined constant pages - assumed 'pages'
What could I do about it?
EDIT
I tried another approach (but with no better results):
renamed the route which redirects to '/' to 'home'
made a LogoutController in app/http/Controllers/Auth
namespace App\Http\Controllers;
use [...]
class LogoutController extends Controller
{
public function logout() {
Auth::logout();
return Redirect::route('home');
}
}
made the route
Route::post('logout', array(
'as' => 'account-sign-out',
'uses' => 'Auth\LogoutController#logout'
));
The error I get is
MethodNotAllowedHttpException in RouteCollection.php line 233:
That's the same error I get when I try to use the default logout defined in auth
You are trying to access the logout page with GET. But this doesn't work because your logout route is a post route.
Change
Route::post('logout', array(
'as' => 'account-sign-out',
'uses' => 'Auth\LogoutController#logout'
));
by
Route::get('logout', [
'as' => 'account-sign-out',
'uses' => 'Auth\LogoutController#logout'
]);
When you go to the /logout route with the method GET(The default when you go to a page) it should work.
I'm getting MethodNotAllowedHttpException in RouteCollection.php line 218:
when i'm posting form within larave-localization route group.
Here is my localized route group:
Route::group([
'prefix' => LaravelLocalization::setLocale(),
'middleware' => [ 'localeSessionRedirect', 'localizationRedirect' ] ], function() {
Route::post('/offerselect', 'SearchController#getCarList');
Route::get('/', 'PageController#index');
});
I have a form inside index.blade php and it posts to /offerselect
but when i post it i get methodnotallowed exception. if i place the post outside of group it works without localization....
check
php artisan routes
to see if you're routes are defined correctly.
update: is that your whole routes.php?
I installed fresh laravel 5.2.29.
My routes.php:
Route::group(['middleware' => ['web']], function () {
Route::get('/a', function () {
return redirect('/b', 302)->with('error', 'error description');
});
Route::get('/b', function () {
return session('error');
});
});
When I go to /a in browser it redirects me to /b, but shows me nothing. What should I do to it show me error description? Or why does not it store flash data?
Basically, if you are running Laravel 5.2.27 and up, do not use the web middleware group. It is applied for you by default as you can see in app/Http/RouteServiceProvider.php:
protected function mapWebRoutes(Router $router)
{
$router->group([
'namespace' => $this->namespace, 'middleware' => 'web',
], function ($router) {
require app_path('Http/routes.php');
});
}
If you try to apply the web middleware again, you'll run into weird problems like what you are currently facing.