Laravel Custom Controller getting 404 error - php

I have created the new controller using command line on laravel
php artisan make:controller PhotoController --resource
just display the string on a function of PhotoController like below
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class PhotoController extends Controller
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function getName()
{
echo 'Dev';
}
Called the controller on route web.php
Route::get('photos', 'PhotoController#getName');
When i trying to load the url of controller
http://localhost/dev_laravel/public/photos
getting 404 Not found error
I also tried
http://localhost/dev_laravel/public/photo/
http://localhost/dev_laravel/public/photo/getname/
I'm beginner or learner for laravel and working on 5.8 version
php artisan route:list
after
Can anyone help me?

Open Terminal
and Run This Command
php artisan serve
Open Second Terminal and run this command
php artisan route:list
And then Your url pattern is like
http://localhost:8000/photos
or
http://127.0.0.1:8000/photos

php artisan serve
it gives a link like http://127.0.0.1:8000/ or your desire port if you set a port for it then just add photos like
http://127.0.0.1:8000/photos

Related

Class Sheets not found

Hey guys I have integrated Google sheets using revolution/laravel-google-sheets following this blog https://drivemarketing.ca/en/blog/connecting-laravel-to-a-google-sheet/
Everything works well on my development environment so I have pushed my code to my staging server to test. After pushing my code to the staging server, I ran the following commands composer update, php artisan config:cache and composer dump-autoload in that order. When I test the flow, I get an exception error
ERROR: Class 'Sheets' not found {"exception":"[object] (Symfony\Component\Debug\Exception\FatalThrowableError(code: 0):
Below is a snippet of the controller code
<?php
namespace App\Http\Controllers\API;
use Sheets;
use App\User;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class MainController extends Controller
{
/**
* Write user details to google sheet
*
* #param $user
*/
public function writeUserToSheets($user)
{
Sheets::spreadsheet('google sheet id')->sheet('users')
->append([
[$user->id, $user->email, $user->first_name, $user->last_name, $user->created_at->toDateTimeString()]
]);
}
}
Am I missing anything? How do I get my code to work on my staging server?

How to create custom controller in Laravel Voyager

I am very new in Voyager.
I have got all the controllers inside TCG\\Voyager\\Http\\Controllers while installing Voyager but didn't find other controllers those I have created using BREAD.
Besides that I want to create custom controller in my Voyager admin panel inside App\\Http\\Controllers\\Voyager . I also followed the steps of Voyager tutorial in Youtube for making custom controller, but couldn't create.
Anybody help please ?
In your config\voyager.php file add your namespace:
'controllers' => [
'namespace' => 'App\Http\Controllers\Back',
],
Then publish voyageres controllers to your namespace
php artisan voyager:controllers
Within that namespace create a new controller derived from VoyagerBreadController
namespace App\Http\Controllers\Back;
use Illuminate\Http\Request;
class SchoolController extends VoyagerBreadController
{
Then you can specify the controller in the bread editor.
NOTE: I did have to refer to mine as Back\SchoolController instead of just SchoolController as I would have expected.
Update:
From version 1.1 now you need to extend VoyagerBaseController instead of VoyagerBreadController.
Add this to your model.
use Illuminate\Database\Eloquent\Builder;
protected static function boot()
{
parent::boot();
static::addGlobalScope('order', function (Builder $builder) {
$builder->orderBy('name', 'asc');
});
}
Try this :
composer dump-autoload
php artisan cache:clear
php artisan config:clear
php artisan view:clear
php artisan route:cache

PHP artisan controller error

I try to make a controller with PHP artisan but when I run command php artisan make:controller TasksController I confront with following error:
In RouteAction.php line 84:
Invalid route action: [App\Http\Controllers\TaskController].
why this error to be occur?
Thanks in Advance.
The error occurs because you're trying to execute TaskController without action. You need to add action to the controller:
Route::get('task', 'TaskController#someAction');
If you don't have a similar route, it means routes are cached with some wrong route. Since Artisan commands do not work, clear this cache manually by deleting this file:
bootstrap/cache/routes.php

Laravel 5: class 'Illuminate\Database\Seeder' not found

Problem I'm currently facing to has been posted here already, yet none of them could solve my one.
I'm talking about database seeder located under url like http://HOSTNAME/laravelfiles/database/seeds/UsersTableSeeder.php. Its content is as follows:
<?php
use Illuminate\Database\Seeder;
class UsersTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* #return void
*/
public function run()
{
// What should be being done, it is being done here :)
}
}
Having opened this file directly (by url given above the code), following error is printed:
Fatal error: Class 'Illuminate\Database\Seeder' not found in /var/www/laravelfiles/database/seeds/UsersTableSeeder.php on line 6
I found possible solution. Doesn't work for me:
composer dump-autoload
<?php
use Illuminate\Database\Seeder;
class UsersTableSeeder extends Seeder
{
}
NOTE: Even the code above produces the same error.
You must run seeder class via command line, not browser.
you should open your command line and change directory to laravel root folder.
then you need to run command:
php artisan db:seed
and check your database.
for more info please check laravel documentation(Laravel Database Seeding)

Laravel 5 - View [home] not found

I ran composer update and now I'm running into an issue. I'm getting this error when I'm trying to load my home view:
InvalidArgumentException in FileViewFinder.php line 140:
View [home] not found.
Yes, files exists in my directory (resources/views, etc.). Name is home.blade.php.
My controller:
<?php namespace Hulahoop\Http\Controllers;
use Hulahoop\Http\Requests;
use Hulahoop\Http\Controllers\Controller;
use Illuminate\Http\Request;
class HomeController extends Controller {
/**
* Display a listing of the resource.
*
* #return Response
*/
public function index()
{
return view('home');
}
}
Route:
Route::get('/', 'HomeController#index');
This was working fine and it's very basic function. What happened? Running on local homestead FYI.
UPDATE: When I run php artisan serve, I can view the home page view fine (i.e. on http://localhost:8000). But on homestead, no dice. What gives?
There seem to be a problem with vagrant and php artisan config:cache.
If you run php artisan config:clear and then try to open the page - you should see it working fine - just make sure you don't cache it via artisan.
Check out [ vendor/config.php ] it's hard-coded for local development.
You need to give executable permission for the view folder 755

Categories