Laravel 5 - NotFoundHttpException - laravel

Here's my routes.php:
<?php
Route::get('/', 'StaticPagesController#index');
Route::get('about', 'StaticPagesController#about');
Route::get('contact', 'StaticPagesController#contact');
Route::get('signup', 'StaticPagesController#signup');
Route::get('login', 'StaticPagesController#login');
Route::post('login', 'LoginController#index');
i'm running my site locally via php artisan serve
d:\xampp\htdocs\some-website>php artisan serve
Laravel development server started on http://localhost:8000/
everything works fine. i can access each page (about, contact, signup, login) with no errors.
however, when i use XAMPP, i can only visit the index page:
localhost/some-website/public
i get a NotFoundHttpException in RouteCollection.php line 143 whenever i visit one of the following:
localhost/some-website/public/about
localhost/some-website/public/contact
localhost/some-website/public/signup
localhost/some-website/public/login
EDIT:
i tried editing my routes.php file to:
<?php
Route::get('/', 'StaticPagesController#index');
Route::get('/about', 'StaticPagesController#about');
Route::get('/contact', 'StaticPagesController#contact');
Route::get('/signup', 'StaticPagesController#signup');
Route::get('/login', 'StaticPagesController#login');
Route::post('/login', 'LoginController#index');
but no luck.

so it turns out my problem was with the project's folder name. i had it in CamelCase notation. changing it to lowercase got things sorted out.
shoutout to those who helped!

Related

Some URLs are 404 in production

I have a Laravel 7 project that I deploy using Deployer and everything works as expected. A few days later, I created a new route, /privacy-policy. I also created a controller and a Blade template. Everything seemed to be working great. However, upon deployment, surprisingly there was a 404 error. All the other links are working fine.
Route
Route::get('/home', 'HomeController#index')->name('home');
Route::get('/privacy-policy', 'HomeController#privacy');
Controller
public function privacy()
{
return view('app.privacy-policy');
}
Even a closure doesn't work.
Route::get('/', function () {
return view('app.privacy-policy');
});
I ran the following commands, but it didn't help.
php artisan cache:clear
php artisan route:clear
php artisan config:clear
php artisan config:cache
Why don't you run php artisan route:list so that you can verify the URI and name are actually correct? For instance if you see 'app.privacy-policy' in the URI column then verify that it's named that and also in your controller. Basically fix your route.
Route::get('app.privacy-policy', 'HomeController#privacy')
->name('app.privacy-policy');
public function privacy()
{
return view('app.privacy-policy');
}

Defining routes in api.php and web.php with same name

I have a route in my api.php file
Route::get('category/{id}/subcategory','SubcategoryController#categoryFinder')->name('cat_to_sub.find');
This route worked fine until i added another route in the web.php file
Route::get('category/{id}/subcategory',function(){return view('subcategories');});
And then when i run php artisan route:list
The URI api/category/{id}/subcategory has no name and i referenced that name all over my files and its throwing all these errors saying route cat_to_sub.find not defined
But when i remove the route in the web.php file everything works.
So whats causing this errors and is there another way to do it?

How to access image from /storage -laravel- from SPA with vuejs

if i put an image in "storage/app/public/img/logo.png" and execute: 
$ php artisan storage:link
How i get that logo.png in vue component?
<img src="storage/app/public/img/logo.png">
The requested it's ok (200) but that image not render, because is an SPA.
Thank you,
Well, after to do:
$ php artisan storage:link
In my component i used:
<img :src="'../storage/img/logo.png'">
thanks,
When you use the storage:link command, you create a symbolic link between your storage/app/public folder and your public/storage folder.
So now you can find your files at the url $BASE_URL/storage/img/logo.png.
I recommend you to use the asset helper function inside your blade template:
<img src="{{ asset('storage/img/logo.png' }}">
NOTE: be sure to set the proper file permissions on the folder or you get an Unauthorized error when trying to access it.
Check config/filesystems.php (ie: unmodified default):
// If server doesn't support "making symbolic links":
// https://medium.com/#shafiya.ariff23/how-to-store-uploaded-images-in-public-folder-in-laravel-5-8-and-display-them-on-shared-hosting-e31c7f37a737
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
Save an image:
$image = $request->file('image'); // something like that
$slug = 'some-slug-99';
$image->storeAs(
'examples' .'/'. $slug,
$image->getClientOriginalName(),
'public'
);
Create the symlink from /storage/app/public to public/storage (ie: your public html folder which makes asset() work in Laravel Blade templates, I think but don't quote me on that)
$ php artisan storage:link
Place the HTML in your Vue component:
<img
v-for="image in example.images"
:key="image.filename"
:src="`/storage/examples/${example.slug}/${image.filename}`"
>
Also, read the docs: https://laravel.com/docs/8.x/filesystem
When using php artisan storage:link you are creating a simbolic link from public/storage to storage/app/public
I'm used to use asset instead regular path: Try using src="{{ asset('storage/app/public/img/logo.png') }}
It is supposed that if you are using a SPA, when a component renders, it will make a new request to get the img
Hope my answer will help someone,
Create a symbolic link by using this command
php artisan storage:link
now use it in you vue template as following
/storage/path/to/file
routes/web.php
For SPA application, Laravel usually render index blade for all incoming requests.
Route::get('/{any}', function () {
return view('index');
})->where('any', '.*');
I changed this route so that all routes except "/storage/**/." locate index blade page.
This way, you can both render SPA and get uploaded image.
Route::any('{all}', function () {
return view('index');
})->where('all', '^(?!storage).*$');
I assume you have already created symlink using php artisan storage:link command.
Take a look Vue js laravel 8 routing
I don't know why no one write their solution clear.
In Laravel and vuejs
When you store files inside laravel storage do as bellow;
create a symlink by running php artisan storage:link it will create a directory inside your-project/public by the name of storage which is not actually a directory that is a link to project/storage directory, if you navigate to your-project/public you will see all the files uploaded into your storage showing here, now you cannot access your file directly from here.
If you have an image stored in this location: storage/app/public/files/logo.png the path to show the image in vue a component will be /storage/files/logo.png please escape app/public parts.
<b-avatar href="#" :src="'/storage/files/logo.png'"></b-avatar>
I hop it help someone.

NotFoundHttpException in RouteCollection.php in laravel 5.4

I created a new project via composer create-project laravel/laravel Test 5.4.* then i go to my browser to see my localhost if its working localhost/test/public and it works it redirect me to the welcome page, but when i tried to test
Route::get('/test', function(){
return 'TEST';
});
Then I go to my localhost/test/public/test it shows me error like
NotFoundHttpException: in RouteCollection.php (line 179)
is it a solved issue?
instead of localhost/test/public/test try localhost/test/public/index.php/test.
of course you can use laravel's own server. it is suitable for most developing usages.

Undo Laravel authentication

I have enabled Laravel authentication using this command: php artisan make:auth. But now I want to get rid of this. Is there any command or a way so that I can do it and remove the effect? Thanks.
There is no command to undo it, but if you check the command at Illuminate\Auth\Console\MakeAuthCommand, you can see what is being changed. If you want to undo it, delete these files & folders if you did not create them:
Files to be removed:
app/Http/Controllers/HomeController.php
resources/views/auth/login.blade.php
resources/views/auth/register.blade.php
resources/views/auth/passwords/email.blade.php
resources/views/auth/passwords/reset.blade.php
resources/views/auth/passwords
resources/views/auth
resources/views/layouts/app.blade.php
resources/views/layouts
resources/views/home.blade.php
And in your routes/web.php, delete these lines:
Auth::routes();
Route::get('/home', 'HomeController#index');
EDIT: Laravel 5.6
The MakeAuthCommand was renamed to AuthMakeCommand. Generated files has not been changed. Only the generated routes has been changed slightly:
Auth::routes();
Route::get('/home', 'HomeController#index')->name('home');

Resources