Display home page in base url without showing /home (Laravel) - laravel

If I type my website url in browser as www.test.com/ then it redirects to www.test.com/home. But I want to see the url in browser as www.test.com only.
routes.php
Route::get('/', array('uses' => 'HomeController#home', 'as' => 'home'));
Route::get('home', array('uses' => 'HomeController#home', 'as' => 'home'));

Try this in your route file:
Route::get('/', 'Admin\HomeController#index');
and remove the extra home route.
See, if that helps.

Route::get('/', array('uses' => 'HomeController#home', 'as' => 'home'));
Keep this route only and remove the next route
It will work as you are expecting then

Related

Laravel route gets wrong controller

I'm building project with Laravel and Vue and i want my categories and tags urls to be like that:
domain.com/some-tag
domain.com/some-category
My web.php:
Route::get('/', ['uses' => '\App\Http\Controllers\IndexController#index']);
Route::get('/{category}', ['as' => 'category', 'uses' => '\App\Http\Controllers\CategoryController#index']);
Route::get('/{tag}', ['as' => 'tag', 'uses' => '\App\Http\Controllers\TagController#index']);
Route::get('/{category}/{article}', ['as' => 'category.article', 'uses' => '\App\Http\Controllers\ArticleController#index']);
I'm getting 404 error on my tags links and i know its because router matches "category" first and uses CategoryController.
What should I do? I don't want to make them unique by adding something like domain.com/tags/tag-name
I've tried to use named routes for my vue component (with Ziggy-js lib) so my link looks like
<a class="tags-block__link" :href="route('tag', {tag: tag.slug}).url()" v-for="tag in tags" :key="tag.id">
But it doesn't help
Why it should not be mixing?
You define Route::get('/{category}' and Route::get('/{tag}'. So if you open /1 in your browser it will always run the first route it is able to find that matches the pattern. So it is always running CategoryController#index yes?
Your routes should be:
Route::get('/category/{category}', ['as' => 'category', 'uses' => '\App\Http\Controllers\CategoryController#index']);
Route::get('/tag/{tag}', ['as' => 'tag', 'uses' => '\App\Http\Controllers\TagController#index']);
Read more at https://laravel.com/docs/7.x/routing
The remaining route should do fine, cause you define it last.

Routes are not working properly

When the user accesses "http://proj.test/" instead of getting the homepage I get:
Sorry, the page you are looking for could not be found.
But if the user accesses "http://proj.test/home" it works.
Also when the user accesses "http://proj.test/conference/create" instead of appear the page with the form to create a conference it appears:
View [app] not found. (View: /Users/johnw/projects/proj/resources/views/conferences/create.blade.php)
Do you know where can be the issue? Should be something about the links or routes but I don't know where is the issue.
Links that I'm using
<a class="logo" href="{{route('home')}}">Homepage</a>
Create Conference
Login
Logout
Register
Routes:
Route::group(['prefix' => '', 'middleware' => 'auth'], function(){
Route::post('/conference/store', [
'uses' => 'ConferenceController#store',
'as' => 'conference.store'
]);
Route::get('/conference/create', [
'uses' => 'ConferenceController#create',
'as' => 'conference.create'
]);
});
Auth::routes();
Route::get('/home', 'HomeController#index')->name('home');
When the user accesses "http://proj.test/" instead of getting the homepage I get:
Sorry, the page you are looking for could not be found.
You have not defined any route for this URL
You can do
...
Route::get('/', 'HomeController#index');
Route::get('/home', 'HomeController#index')->name('home');
...
Very simple answer - you need a Route::get('/', ...) route.
Add this to your Routes instead:
Route::group(['middleware' => ['guest']], function(){
Route::get('/', 'WelcomeController#index');
// WelcomeController is my own example, yours will differ...
});
This way it'll check to see if there's an auth or not and will redirect accordingly.

DaveJamesMiller Breadcrumbs Error - Laravel

I am currently trying to set up breadcrumbs for my Laravel 5 application. Unfortunately, I am currently being presented with this error when I access localhost:8888/auth/login:
ErrorException in
/Users/ben/Sites/laravel/vendor/davejamesmiller/laravel-breadcrumbs/src/CurrentRoute.php
line 29
The current route (GET /auth/login) is not named - please check
routes.php for an "as" parameter
Routes.php:
Route::get('auth/login', 'Auth\AuthController#getLogin',
['as' => 'login', 'uses' => 'Auth/AuthController#getLogin']);
The error is shown with or without the ['as' => 'login', 'uses' => 'Auth/AuthController#getLogin'] addition.
Breadcrumbs.php
Breadcrumbs::register('login', function($breadcrumbs)
{
$breadcrumbs->parent('home');
$breadcrumbs->push('Login', route('login'));
});
Thank you for your help.
I resolved this issue by changing the route to the following:
Route::get('auth/login',
['as' => 'login', 'uses' => 'Auth/AuthController#getLogin']);
You can only declare which controller method you're using once.

Laravel: Named route not found

I have the following named route in routes.php:
Route::get('/', 'DefaultController#index', array('as' => 'home'));
Then, I try to get a link to the route in another view (404.blade.php), based on docs:
Go to homepage
However, the page with the code above thows this: Error in exception handler: Route [home] not defined. I tried using simply route('home') as well.
What am I missing?
The syntax for named routes is a bit different
Route::get('/', array('as' => 'home', 'uses' => 'DefaultController#index'));

Facing an issue with routing - Laravel

I started working with Laravel last week and I'm facing a minor problem with routes.
when i do the following:
Route::group(array('before' => 'auth'), function() {
Route::resource('admin', 'VacatureController');
Route::get('admin/test', array('uses' => 'VacatureController#create'));
Route::post('admin/test', array('uses' => 'VacatureController#store'));
});
and i go to admin/test, i get an empty page.
when i change admin/test to something like test/test like:
Route::group(array('before' => 'auth'), function() {
Route::resource('admin', 'VacatureController');
Route::get('test/test', array('uses' => 'VacatureController#create'));
Route::post('test/test', array('uses' => 'VacatureController#store'));
});
it works fine. I looked itup in the documentation, but i didn't become anything wiser.
Can someone please enlighten me?
Try putting the Route::resource as the last route. Laravel will try all routes in the order you put them in the route file, so when you put the resource route first only this one will be checked because it expects all admin routes to be there.
Route::group(array('before' => 'auth'), function() {
Route::get('admin/test', array('uses' => 'VacatureController#create'));
Route::post('admin/test', array('uses' => 'VacatureController#store'));
Route::resource('admin', 'VacatureController');
});

Resources