laravel on windows cant find views - php

Hello i installed laravel 4.2 on my windows pc and get error that view cannot by foundet
InvalidArgumentException
View [layout.index] not found.
my controller content
protected $layout = 'layout.index';
public function home()
{
return $this->layout->content = View::make('content_index.home');
}
but realy file exists 'views/layout/index.blade.php'
its kinda bug or something ?

The folder is actually /layouts, so your view should be located at :
protected $layout = 'layouts.index';

my problem is start after I run this on local:
php artisan config:cache
after that I run this in vagrant and solve problem.
open ssh
php artisan config:cache

Related

Getting "MongoDB\Driver\Manager Not Found" when using view composers in Laravel

I am using Laravel 7 and Jensseger's MongoDB package.
Everything works fine, except for this:
When I issue php artisan view:clear, I get MongoDB\Driver\Manager Not Found error.
I already have installed the latest version of MongoDB module for php 7.4 and everything else works fine. Meanwhile, I am using a dockerized environment. So, I am totally clueless why this is happening when I try to clear cached views.
This is my ViewServiceProvider file:
class ViewServiceProvider extends ServiceProvider
{
public function register()
{
}
public function boot(HeaderRepository $repository)
{
$header = $repository->getHeader();
View::composer('errors::*', function($view) use($header){
$view->with([
'header' => $header,
]);
});
}
}
My purpose is to create a customized 404 error page, but the header has to be fetched from MongoDB and shared between customized error pages. That's why I'm using view composers. Any other solution is welcome as well.
I suppose, you enter command php artisan view:clear from a local console.
You have choice:
Install mongo drive to your local interpreter
Use artisan from docker container eg docker exec {PHP_CONTAINER} php artisan view:clear

Q: Laravel 8 - images don't show on production server

I have shared my Laravel project, but the images don't show on the production. On the other hand, the project is working perfectly locally, but I faced a problem when I want to run php artisan storage:link on the server in order to show images.
Server OS:Linux GNU/Linux
PHP version : 7.4
Laravel version: 8
yf*******#sg3pl***** [~/a***]$ php artisan storage:link
ErrorException
symlink(): No such file or directory
at vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php:315
311▕ */
312▕ public function link($target, $link)
313▕ {
314▕ if (! windows_os()) {
➜ 315▕ return symlink($target, $link);
316▕ }
317▕
318▕ $mode = $this->isDirectory($target) ? 'J' : 'H';
319▕
+15 vendor frames
16 artisan:37
Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
Thanks in advance.
My similar problem was solved by adding FILESYSTEM_DRIVER = public in .env, you can try this.
I have been solving this issue.
I was wrong, for I deleted the public folder from my project. Moreover, when I deleted the public folder from my project folder, I couldn’t link a storage folder, so I should keep the public file in the main folder project.
=> cd FILE_PROJECT in the root.
=> mkdir public .
=> php artisan storage:link
This way works for me.

Why is authorize() not working in production as it is in development enviroment?

When I upload my project to web server and when I try to login I get 403 error but what confuses me is that it is working just fine in development enviroment. For example this is my controller function :
public function show($user){
$user = \App\User::find($user);
$this->authorize('view', $user->supplier);
return view("/Suppliers/supplier", compact('user'));}
and this is my policy:
public function view(User $user, Supplier $supplier)
{
return $user->id === $supplier->user_id;
}
And it goes on for all authorize() functions. This is my first time deploying laravel app so any help is much appreciated.I am running laravel 8.0.1 version. And also I ran php artisan cache:clear
php artisan route:clear php artisan config:clear and php artisan view:clear

Laravel console command trait method not found

I have a Laravel project that has been deployed with Forge and had OPCache enabled using Forge. I noticed last week that when I pushed some changes, the changes that were in the views and in the controllers were present on the server, but custom artisan commands that I run don't recognize updates.
Put another way, updates to the blades are showing on the screen. Updates that I have added to the controllers are changing the way information is passed to the blade files, but I have a custom artisan command that runs a series of methods in a trait. The actual file on the server shows the new method that I pushed, but when I run the artisan command in the CLI, it says that the method cannot be found.
I have stopped, restarted, and reloaded OPCache countless times. I have restarted Nginx. I have disabled OPCache and restarted PHP. It is still saying that the method is not found. Does anyone have any ideas?
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Traits\FTPImportsTrait;
class CheckFTPImports extends Command
{
use FTPImportsTrait;
protected $signature = 'checkForImports';
protected $description = 'Check for imports...';
/**
* Create a new command instance.
*
* #return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* #return mixed
*/
public function handle()
{
$this->checkBankImports();
}
}
-----------
<?php
namespace App\Traits;
trait FTPImportsTrait;
{
public function checkBankImports()
{
dd('YOU ARE NOT CRAZY');
}
}
$ php artisan checkForImports
$ method checkBankImports does not exist.
UPDATE:
It has to be some sort of configuration issue on the server. I just deployed the project to a fresh DO droplet and the command works as expected.
It only happened in the production environment for me.
Running:
php artisan clear-compiled
deleted the cached version and solved my issue.
Thanks a ton to #num8er.

Laravel view not found exception

I have problem with laravel view is not found by route function I did composer dumpautoload but no use
ArticleController.php
<?php
class ArticleController extends BaseController
{
public function showIndex()
{
return View::make('index');
}
public function showSingle($articleId)
{
return View::make('single');
}
}
//Route
Route::get('index', 'ArticleController#showIndex');
InvalidArgumentException
View [index] not found.
open: /opt/lampp/htdocs/laravel-project/bootstrap/compiled.php
foreach ((array) $paths as $path) {
foreach ($this->getPossibleViewFiles($name) as $file) {
if ($this->files->exists($viewPath = $path . '/' . $file)) {
return $viewPath;
}
}
}
throw new \InvalidArgumentException("View [{$name}] not found.");
}
protected function getPossibleViewFiles($name)
Server/Request Data
REDIRECT_UNIQUE_ID UfWlAn8AAQEAABR2VakAAAAF
REDIRECT_STATUS 200
UNIQUE_ID UfWlAn8AAQEAABR2VakAAAAF
HTTP_HOST localhost
HTTP_USER_AGENT Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:22.0) Gecko/20100101 Firefox/22.0
HTTP_ACCEPT text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
HTTP_ACCEPT_LANGUAGE en-US,en;q=0.5
HTTP_ACCEPT_ENCODING gzip, deflate
HTTP_COOKIE laravel_session=f94fpel78jn89nhah32mflqn15
HTTP_CONNECTION keep-alive
HTTP_CACHE_CONTROL max-age=0
PATH /usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
LD_LIBRARY_PATH /opt/lampp/lib:/opt/lampp/lib
SERVER_SIGNATURE
SERVER_SOFTWARE Apache/2.4.4 (Unix) OpenSSL/1.0.1e PHP/5.4.16 mod_perl/2.0.8-dev Perl/v5.16.3
SERVER_NAME localhost
SERVER_ADDR 127.0.0.1
SERVER_PORT 80
REMOTE_ADDR 127.0.0.1
DOCUMENT_ROOT /opt/lampp/htdocs
REQUEST_SCHEME http
CONTEXT_PREFIX
CONTEXT_DOCUMENT_ROOT /opt/lampp/htdocs
SERVER_ADMIN you#example.com
SCRIPT_FILENAME /opt/lampp/htdocs/laravel-project/public/index.php
REMOTE_PORT 50211
REDIRECT_URL /laravel-project/public/index
GATEWAY_INTERFACE CGI/1.1
SERVER_PROTOCOL HTTP/1.1
REQUEST_METHOD GET
QUERY_STRING
REQUEST_URI /laravel-project/public/index
SCRIPT_NAME /laravel-project/public/index.php
PHP_SELF /laravel-project/public/index.php
REQUEST_TIME_FLOAT 1375053058.123
REQUEST_TIME 1375053058
This error also occurs when you try to move the whole project directory to other path. And you happened to run the following commands below BEFORE you move.
php artisan optimize --force
php artisan config:cache
php artisan route:cache
Mine error message shows like this
As you can see the old path was written in the compiled.php. So, to fix the problem. Simply run the same command AGAIN under the project folder in your new folder location.
php artisan optimize --force
php artisan config:cache
php artisan route:cache
Hope this helps.
This happens when Laravel doesn't find a view file in your application. Make sure you have a file named: index.php or index.blade.php under your app/views directory.
Note that Laravel will do the following when calling View::make:
For View::make('index') Laravel will look for the file: app/views/index.php.
For View::make('index.foo') Laravel will look for the file: app/views/index/foo.php.
The file can have any of those two extensions: .php or .blade.php.
This command works for me
php artisan config:cache
As Laravel doc says that by default, Laravel is configured to use the file cache driver, which stores the serialized, cached objects in the filesystem. So it needs to recache the file system so that newly added views and route are available to show. I also not sure why laravel needs to recache actually
This might be possible that your view is present even though it shows the error. So to solve this issue you need to stop the server and run this command on the terminal.
php artisan config:cache
then restart the server
In my case I had to run php artisan optimize:clear in order to make everything to work again.
Somewhat embarrassingly, I discovered another rather trivial cause for this error: I had a full stop in the filename of my blade file (eg resources/views/pages/user.invitation.blade.php). It really did make sense at the time!
I was trying to reference it like so: view('pages.user.invitation')
but of course Laravel was looking for the file at resources/views/pages/user/invitation.blade.php and throwing the view not found.
Hope this helps someone.
Just in the controller call
return View('index');
without
::make
As #deanchiu said it may happen when you move the whole project to another path or server.
But in my case I had no access to command line on server and running following commands BEFORE I upload my project helped me.
> php artisan route:clear
> php artisan config:clear
In my case I was calling View::make('User/index'), where in fact my view was in user directory and it was called index.blade.php. Ergo after I changed it to View#make('user.index') all started working.
I was having the same error, but in my case the view was called seeProposal.
I changed it to seeproposal and it worked fine...
It was not being an issue while testing locally, but apparently Laravel makes a distinction with capital letters running in production. So for those who have views with capital letters, I would change all of them to lowercase.
check your blade syntax on the view that said not found
i just fix mine
#if
#component
#endif
#endcomponent
to
#if
#component
#endcomponent
#endif
Use this on your cmd then run your project.
php artisan config:cache php artisan route:cache php artisan
controller:cache php artisan optimize:clear
If your path to view is true first try to config:cache and route:cache if nothing changed check your resource path permission are true.
example: your can do it in ubuntu with :
sudo chgrp -R www-data resources/views
sudo usermod -a -G www-data $USER
In addition to these answers, if your view is in an unusual directory for the project, you'll have to add the following to /config/view.php
'paths' => [
resource_path('views'),
resource_path('../path/from/project/route/to/view')
],
If you are not accessing files as root user you shall change access of files
Change Access group to Access files
Also, others to Access files
it's work for me
If you are using GIT in your project don't forget make git add . and commit before of move the project to another side and also don't forget clean the cache.
In my case, Laravel 5.3
Route::get('/', function(){
return View('test');
});
test.blade.php was not rendering but some other views were rendering on localhost via XAMPP on mac. Upon running artisan server, the view started rendering for same url over XAMPP.
php artisan serve
To avoid any such scenario, one should test the Laravel apps with artisan server only.
Create the index.blade.php file in the views folder, that should be all
I had the same error. I created a directory under views direcotry named users and created an index.blade.php file in it. When calling this file you should write users.index to indicate your path. Or just create index.blade.php file under views. hope this will help someone who gets the same problem

Categories