InvalidArgumentException View [back.admin] not found - php

I have checked the path, and I checked the route. Unfortunately, nothing helps. I'm getting an error here:
DashboardController.php
class DashboardController extends Controller
{
public function admin()
{
return view('back.admin');
}
}
Route
Route::get('/admin', [App\Http\Controllers\DashboardController::class, 'admin'])
->name('back.admin');
InvalidArgumentException
View [back.admin] not found.
http://localhost:8000/admin

We should put the view file in the following directory to make it work:
resources/views/back/admin.blade.php

Return view ('back.admin') in the admin function in the controller
There is no file named views / back / admin under the resources folder. Can you check the file path?

Related

Laravel 5.4 controller doesn`t show page

I have folder "aboutus" which contains 'index.blade.php' file and folder "thanks".
Folder "thanks"contains also 'index.blade.php'
My route for both of them:
Route::resource('admin/aboutus', 'AdminAboutusController',['names'=>[
'index'=>'admin.aboutus.index',
'create'=>'admin.aboutus.create',
'store'=>'admin.aboutus.store',
'edit'=>'admin.aboutus.edit'
]]);
Route::resource('admin/aboutus/thanks', 'AboutThanksController',['names'=>[
'index'=>'admin.aboutus.thanks.index',
'create'=>'admin.aboutus.thanks.create',
'store'=>'admin.aboutus.thanks.store',
'edit'=>'admin.aboutus.thanks.edit'
]]);
I have created controller for aboutus and thanks separately (AdminAboutusController and AboutThanksController)
AdminAboutusController index funnction returns view which i am able to see
public function index() { return view('admin.aboutus.index'); }
But controller AboutThanksController doesn`t shows me my page, it shows me white blank
public function index() { return view('admin.aboutus.thanks.index'); }
on php artisan route:list i can see that route is aviable.
Why it happens and how can I fix it?
Put thanks route above about us route
Route::resource('admin/aboutus/thanks', 'AboutThanksController',['names'=>[
'index'=>'admin.aboutus.thanks.index',
'create'=>'admin.aboutus.thanks.create',
'store'=>'admin.aboutus.thanks.store',
'edit'=>'admin.aboutus.thanks.edit'
]]);
Route::resource('admin/aboutus', 'AdminAboutusController',['names'=>[
'index'=>'admin.aboutus.index',
'create'=>'admin.aboutus.create',
'store'=>'admin.aboutus.store',
'edit'=>'admin.aboutus.edit'
]]);
Posting as an answer to close the question:
You have admin.aboutus.thnx.index but your folder is admin/aboutus/thanks/index
Please change to admin.aboutus.thanks.index and it should work
using route:list you are able to see list of routes but return view() function don't take route as a parameter. You have to give the file name and path.For example you want to show thanks.blade.php file which is inside admin/aboutus of your view folder. So you have to write:
return view('admin.aboutus.thanks');

I am unable to access Laravel view

I have just created one of about view in view/about.blade.php, and I am accessing this from localhost/myproject/public/about, but it's not working.
However, localhost/myprojects/public/ is working fine; about view has been created on same parameters as welcome by default in Laravel.
Firstly the information is not sufficient to say anything.Please provide your route.Also its important how you are running your project ,is it via Xampp(or Lampp whatever is there) or "php artisan serve"
but looking from your working directory "localhost/myprojects/public" I guess its not by the command . Try localhost/myprojects/public/about.blade.php or run it by php artisan serve and try route localhost:8000/about
Have you added particular routing to web.php file?
Route::get('about', function () {
return view('about');
});
https://laravel.com/docs/5.7/routing
Which error are you getting?
404 - Not found
Route::get('/about', function () {
return view('about');
});
Check routes
php artisan route:list
Laravel is a MVC Framework, Which means You Have a Controller which procede some logic when some request come in and interact with the model if need, after that the controller return some view.
And because you whan to acccess your view file, you must past through controller, and that controller will render the view. Because the views folder is not in the \public dicretory as subdirectory you can't access to It with url like localhost/myproject/public/about even if you get access to it, you will not get HTML, you'll get some plain text with Blade tags. It's a must to return view in you controller by rendering it, somewhere in the background Laravel procede all Blade Tag and return HTML that correspond to that tags.
What I can suggest you Is to create some route in your route file like this
Route::get('/about', function(Request $request){
// Automatically Laravel will look this file in the view directory
return view('about');
});
Or you can go with the controller like procedure by creating some controller, go in your terminal and execute
php artisan make:controller AboutController
this will generate a file name AboutController.php in app\Http\Controllers diretory within witch you will found
namespace App\Http\Controllers;
class HomeController extends Controller
{
}
after that add
public function index()
{
return View::make('about');
}
Don't forget to include use the Illuminale\Supports\Facades\View on top of your file
And one more important thing which left is to configure the Route, for that go in routes directory in the web.php file add
Route::get('/about', 'AboutController#index')->name('about');

Access Controller From Route In Slim

I have Some Routes On \src\routes.php
$app->get('/coba', 'App\controllers\HomeController:getfromcontroller');
And in myapp/app/controllers/HomeController.php like this
public function getfromcontroller((Request $request, Response $response){
$response->withStatus(200)->write('Hello Motehr!');
}
and if i'am access http://localhost/myapp/public/coba thats errror
Type: RuntimeException Message: Callable
App\controllers\HomeController does not exist File:
C:\laragon\www\depoapi\vendor\slim\slim\Slim\CallableResolver.php
Line: 90
Maybe you forgot to call the correct namespace:
$app->get('/coba', ['**YOURAPP**\App\controllers\HomeController', 'getfromcontroller']);
They are three things that can happen here.
Are all your URLs being redirected to the index.php in your public folder? in your case
myapp/public.index.php
Make sure you rename your controller folder to Controller and ensure your function is in the controller class.
Try the solution in question 47724219 where you have to use the absolute namespace.

Showing wrong view in laravel 5.4

I am using laravel 5.4 and trying to get index page, i am using following routes
Route::get('/',
['as' => 'home_page',
'uses' => 'Controller#index']);
and index function in controller looks like this:
public function index()
{
return view('index');
}
But when I visit mydomain.com, I get a different view than index.blade.php.
and it is fine when I use mydomain.com/? or on my local server.
I have searched everywhere in my code and in a google, but didn't found anything, any help?
ie: let me know if any further information required.
First make sure you are calling the right controller, and this dont have a specific middleware blocking the acess to your index method and index.blade.php is inside view folder.
If all of this is fine try this code on your rotes file:
Route::get('', function () {
return view('index');
})
Try this.
First use the make:controller Artisan command to create a controller file. let's say it is homeController.
php artisan make:controller homeController
Then in the homeController file write your code to get the view.
<?php
namespace App\Http\Controllers;
class homeController extends Controller
{
public function index()
{
return view('index');
}
}
Then define a route to this controller.
Route::get('/', 'homeController#index');
For more information please refer https://laravel.com/docs/5.5/controllers
There was a cached view saved on my server, I used
php artisan cache:clear and it got fixed. Thank you everyone for the support.

"Whoops, looks like something went wrong." Laravel 4.1

Okay, so I've just gotten around to checking out Laravel 4.1, I've hit a problem and I don't understand why? The problem is that I get this message on the screen "Whoops, looks like something went wrong." but I haven't really done anything. I've created a view, a controller and added a route and this is what is in these files
VIEW
<h1>Author's home page</h1>
CONTROLLER
class AuthorsController extends BaseController {
public $restful = true;
public function getIndex () {
return View::make('authors.index'); //authors.index because it's in the authors folder within the views folder
}
}
and ROUTE
Route::get('authors', 'AuthorsController#getIndex');
So logic dictates that when I go to the authors URL it should load the getIndex function within the AurhorsController page and show the index.blade.php file which is in views > authors.
If so then I have no idea why this is not working! any help would be appreciated. Thanks in advance.
EDIT 1
This is the actual error
throw new NotFoundHttpException();
EDIT 2
You should remove public $restful = true; but it's not a problem for NotFoundHttpException
// Path: app/controllers/AuthorsController.php
class AuthorsController extends BaseController {
// public $restful = true;
public function getIndex () {
return View::make('authors.index');
}
}
According to your route given below:
Route::get('authors', 'AuthorsController#getIndex');
It should work if you make a GET request, make sure you made the request from browser's address bar and url was like yourdomain.dev/authors or http://localhost/yourapp/authors. Also you may run following command from command prompt/terminal (within your project directory):
composer dump-autoload
Looks like Laravel's trying to access the public folder and fails, because there's no file named authors in that folder, and also no route named public/authors. You'll want to go to http://localhost:8081/branch/authors instead, assuming that your installation resides in http://localhost:8081/branch.

Categories