Laravel Routing in package - php

I'm working on a laravel package but my routes.php can't find my controller...
My package is called Blackbird\Bluebird and in my app.php settings file dashboard_uri is equal to 'admin'.
If I replace the Route::controller to Route::resource it al works find in my public directory, if I then switch to public/admin I get this error: Class Blackbird\Bluebird\Controllers\DashboardController does not exist. Note that it if I use Route::controller I get the error on the public directory aswell.
I already run composer dump-autoload...
What are my options?
routes.php:
$dashboardUrl = Config::get('bluebird::app.dashboard_url');
Route::controller($dashboardUrl, 'Blackbird\Bluebird\Controllers\DashboardController');
DashboardController.php:
<?php namespace Blackbird\Bluebird\Controllers;
class DashboardController extends BaseController {
public function getIndex()
{
return View::make('bluebird::dashboard'); // Opens View/Dashboard.blade.php
}
// Some more code...
}

Related

InvalidArgumentException - No hint path defined

I am trying to add controller view in my existing project that consider model view controller structure in php with laravel.
class CashFlowdataController extends Controller {
public function index() {
return view('CashFlowdata::create');
}
}
When I implement this, it shows me error for,
InvalidArgumentException
No hint path defined for [CashFlowdata].
I have added file in route.php and web.php as added other controller data. Only for this one it shows message like this.
you code is wrong you should to something like this
class CashFlowdataController extends Controller {
public function index() {
return view('CashFlowdata.create');
}
}
here CashFlowdata.create
its means in laravel
folder structure should be
view>CashFlowdata>create.blade.php
laravel view() function is a helper to load view file
ref link https://laravel.com/docs/8.x/helpers#method-view
I had the same issue in nwidart/laravel-modules due to module.json file was miss place.
I move the file to the root of module now working fine.

Class App\Http\Controllers\EditareProfilController does not exist

I am very new in Laravel and this is my first project. I have this problem and I don`t know how to fix it.
This is my directory
I am sure I have tried all I know
This is my controller:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class EditareProfilController extends Controller
{
public function __construct()
{
$tasdhis->middlewasdare('auasdth');
}
public function index()
{
return vasdasdiew('editaasdasdasdeprofil');
}
}
and this is my route:
Route::get('/editarasdasdeprofil', 'EditareProfilasdasdasdontroller#index')->name('editarepasdasdasdrofil');
The default location for controllers is app\Http\Controllers if you add a folder just add it to your route in order to laravel localize it. In your code you are storing your controller under the Auth folder.
Update your route to:
Route::get('/editareprofil', 'Auth\EditareProfilController#index')->name('editareprofil');
And also don't forget to update the namespace.
namespace App\Http\Controlllers\FOLDER;

when I move my laravel project to a server this error appears FatalErrorException in EloquentUserProvider.php line 136: Class '\App\user' not found

I am trying to move my laravel project to a hostgator shared hosting (I have acces to the terminal but not as root so I can not install anything), I did it Separating my public folder from the rest of it, so in a public_html I put all the folders and archives that are in the public folder of laravel, and in another folder call laravel i move the rest of my project.
I already change this in index.php in the public_html folder:
require __DIR__.'/../laravel/bootstrap/autoload.php';
$app = require_once __DIR__.'/../laravel/bootstrap/app.php';
after all this the home page is running just fine but when I try to sign in this error appears:
FatalErrorException in EloquentUserProvider.php line 136:
Class '\App\user' not found
I do not know what to do.
here is are my routes:
Route::get('/', 'SessionController#create');
Route::post('/', 'SessionController#store');
Route::get('/logout', 'SessionController#destroy');
Route::get('/cliente', function () {
return view('sessions.homeCliente');
});
Route::get('/staff', function () {
return view('sessions.homeStaff');
and here is my session controller:
<?php
namespace App\Http\Controllers;
use App;
use Auth;
use Illuminate\Http\Request;
class SessionController extends Controller
{
function __construct()
{
$this->middleware('guest', ['except'=>'destroy']);
}
public function create(){
return view('sessions.create');
}
public function store(){
//intento de iniciar session
$request=request(['usuario','password']);
if(!auth()->attempt($request)){
return redirect('/prueba');
}
//redirigir a donde se necesite
if(User::getCliente($request['usuario'])==0){
return redirect('/staff');
}
return redirect('/cliente');
}
}
I do not what to do.
There is no \App\user
It must be \App\User
Usually newbies are careless about letter case, because Windows basically ignores them; but Linux does not, hence moving to a server (which is usually Linux) introduces new errors.

Laravel 5.3 NotFoundHttpException in RouteCollection.php

I have just installed laravel 5.3 and created a new controller. I have defined the routes but i am not getting to this url. I have written this code in routes/web.php file. Here is my routes code :
Routes file:
Route::resource('users','UsersController#getIndex');
Controller file:
namespace App\Http\Controllers;
class UsersController extends Controller
{
public function getIndex()
{
dd("test");
}
}
When you set routes like
Route::resource('users','UsersController#getIndex');
Routes will be created some thing like
App\Http\Controllers\UsersController#getIndex#store
App\Http\Controllers\UsersController#getIndex#index
App\Http\Controllers\UsersController#getIndex#create
and so on..
Change routes file as
Route::resource('users', 'UsersController');
And then rename controller method to
class UsersController extends Controller
{
public function Index()
{
dd("test");
}
}
It should work fine.
Try this one
Route::match(array('GET', 'POST'), 'users', 'UsersController#getIndex');
As, you will get access to only predefined methods through resource route.
Route::resource('users','UsersController');

Laravel Controller doesn't exist, even though it clearly exists

The error I'm getting is that the controller doesn't exist even though I know it does, here's the code.
Route.php
Route::get('mdpay/template', array("uses" => "templateController#index"));
templateController.blade.php
class templateController extends BaseController {
public function index()
{
echo "made it";
}
}
Why might I be getting this error: Class TemplateController does not exist
================= UPDATE: ==================
Ok, so I've created the correct route, renamed my file, and corrected the class name and I'm still coming up with that error.
File Names:
templateController.php
// File Name: TemplateController.php
class TemplateController extends BaseController {
public function index()
{
// app/views/myView.blade.php
echo "hello";
}
}
My route is:
Route::get('mdpay/template', array("uses" => "TemplateController#index"));
Still receiving Controller Doesn't Exist error. All my other controllers (3 others) are working except this one.
If you are using the standard composer classmap autoloader you need to composer dumpautoload everytime you create a new file.
So to create a new controller with the standard composer setup given by Laravel:
Create a new file in app/controllers named TemplateController.php
Open up terminal and run composer dumpautoload
As previous users have said, only view files should end with .blade.php.
If you're using Laravel 8, add this line to your RouteServiceProvider.php (you can search it by using CTRL + P):
protected $namespace = 'App\Http\Controllers';
This solved the issue for me.
It should be:
// File Name: TemplateController.php
class TemplateController extends BaseController {
public function index()
{
// return "made it"; // or
// app/views/myView.blade.php
return View::make('myView');
}
}
Route for that:
Route::get('mdpay/template', array("uses" => "TemplateController#index"));
Use blade in a Blade view, i.e: myView.blade.php basically stored in app/views/ folder. Read more about blate template on Laravel website.
Controllers live in the app/controllers directory and should remain there unless you have your own namespaced structure.
The reason you're getting a Class TemplateController does not exist is because it doesn't, firstly, your class is called templateController and secondly, it exists as templateController.blade.php which wouldn't be loaded in this way.
Blade files are for views, and only views within app/views or a custom views directory should end with .blade.php.
Create the file app/controllers/TemplateController.php and add the following code to it.
class TemplateController extends BaseController {
public function index()
{
echo "made it";
}
}
Now on the command line, run the command composer dumpautoload and change you route declaration to:
Route::get('mdpay/template', array('uses' => 'TemplateController#index"));
Now it should all work.
In case you're using Laravel 9 and the error is like Illuminate\Contracts\Container\BindingResolutionException and Target class <controller name> does not exist. when trying php artisan route:list on terminal.
This is the setup that I do:
Add protected $namespace = 'App\\Http\\Controllers'; to RouteServiceProvider.php
Add 'namespace App\Http\Controllers;' to the controller file.
Do php artisan optimize on terminal
(Just to make sure the route already there) Do php artisan route:list again on terminal, and the controller route should be displayed.

Categories