Laravel with PhpStorm, Method findOrFail not found - laravel

I am using PhpStorm v2021.2, have Laravel plugin (by Daniel Espendiller v0.15.4) installed and enabled, Laravel Query (by Ernestas Kvedaras v2.0.6) and I am also using barryvdh/laravel-ide-helper v2.10.0. I updated composer.json with this bit of code:
"scripts": {
"post-update-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postUpdate",
"#php artisan ide-helper:generate",
"#php artisan ide-helper:meta"
],
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"#php artisan ide-helper:generate",
"#php artisan ide-helper:meta",
"#php artisan package:discover --ansi"
],
so it regenerates all meta and helpers and it successfully creates files .phpstorm.meta.php and _ide_helper.php.
All my models do extend Illuminate\Database\Eloquent\Model. Not directly, I also wrote a BaseModel with some of default properties, so it looks like this:
BaseModel.php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class BaseModel extends Model
{
//
}
Client.php
namespace App\Modules\Clients\Entities;
use App\Models\BaseModel;
...
class Client extends BaseModel
{
//
}
But I am still seeing Method 'findOrFail' not found in \App\Modules\Clients\Entities\Client. What else can I do to make this notice go away?

Related

Illegal string offset 'name' error calling component from blade

In my Laravel 8 app I created new component with command
php artisan make:component Admin/Auth/loggedUserHasPermissions
and I have error with sending parameter to it from blade file :
Illegal string offset 'name' (View: /mnt/_work_sdb8/wwwroot/lar/AdsBackend8/resources/views/test.blade.php)
On row in resources/views/test.blade.php :
<x-logged-user-has-permissions :logged-user="getLoggedUser()" />
getLoggedUser is funnction in helper file.
and in app/View/Components/Admin/Auth/loggedUserHasPermissions.php
<?php
namespace App\View\Components\Admin\Auth;
use Illuminate\View\Component;
use Spatie\Permission\Models\Permission;
use Spatie\Permission\Models\Role;
class loggedUserHasPermissions extends Component
{
private $loggedUser;
private $hasAdminRole;
public function __construct($loggedUser)
{
$this->loggedUser = $loggedUser;
$this->hasAdminRole = false;
}
public function render()
{
I follow camelCase / kebab-case rules written here https://laravel.com/docs/8.x/blade#passing-data-to-components
running commands
php artisan config:cache
php artisan route:cache
php artisan cache:clear
php artisan view:clear
php artisan clear-compiled
composer dump-autoload
did not help
How it can be fixed?
Thanks!

Laravel class undefined after config:clear

App\Constant\ProductConstant.php
<?php
namespace App\Constant;
use App\Constant\BaseConstant;
class ProductConstant extends BaseConstant {
const TITLE = "title";
}
Product.php
<?php
namespace App\Models;
use App\Constant\ProductConstant;
use Illuminate\Database\Eloquent\Model;
class Product extends Model
{
protected $table = 'products';
protected $fillable = [ProductConstant::TITLE, ProductConstant::IMAGE, ProductConstant::EXPIRY_DATE, ProductConstant::MAX_PARTICIPANTS, ProductConstant::TOTAL_PARTICIPANTS];
Error
Undefined class constant 'App\Constant\ProductConstant::TITLE'
After I've executed php artisan config:clear. May I know what's the reason?
do not run php artisan config:clear in local system , it may break your project
delete this file bootstrap/cache/config.php
and run project again
run php artisan cache:clear to clear cache of .env file

php artisan vendor:publish mervick/emojionearea

In installation no describe process publishing this package.
But I would like to setup it.
Laravel 5.6
composer require mervick/emojionearea ^3.0.0
and I need to copy from folder /vendor to /public/vendor using
php artisan vendor:publish
I created file /vendor/mervick/emojioneareaServiceProvider.php
and added lines:
public function boot()
{
$this->publishes(
[
__DIR__ . '/dist' =>
public_path('vendor/mervick/emojionearea/dist'),
],
'emojionearea'
);
}
also, I added lines to /config/app.php
//ServiceProviders
Mervick\EmojioneArea\EmojioneAreaServiceProvider::class,
//Aliases
'EmojioneArea'=> Mervick\EmojioneArea\EmojioneAreaServiceProvider::class,
and run command :
php artisan vendor:publish
also, I used the command:
php artisan vendor:publish --provider="Mervick\EmojioneArea\EmojioneAreaServiceProvider"
Any help.Thanks.
Please follow below steps i have tried moved files to public/vendor folder by updating below steps. Its works fine.
Service provider file.
<?php
namespace mervick\emojionearea;
use Illuminate\Support\ServiceProvider;
class EmojioneAreaServiceProvider extends ServiceProvider
{
/**
* Bootstrap services.
*
* #return void
*/
public function boot()
{
$this->publishes([
__DIR__.'/../dist' => base_path('public/vendor/dist'),
]);
}
}
In your root composer.json file add your vendor for identify the service provider.
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/",
"Mervick\\EmojioneArea\\": "vendor/mervick/emojionearea/src"
}
}
Like you said don't forgot to add the service provider in config/app.php
Mervick\EmojioneArea\EmojioneAreaServiceProvider::class,
If everything works fine for you. Please make it as correct answer.:-)

php artisan make:auth in laravel 5 have a bug

In laravel 5.2 after I use php artisan make:auth -> it download some package fine and I also can open the page like this:
but after I click the link for login, it always error like this:
at kernal.php [ app/Http/Kernal.php ]
Move StartSession::class and ShareErrorsFromSession::class to protected
Eg:
protected $middleware = [
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
];

Laravel 4 Can't find BaseController from namespaced controller

I'm trying to structure my Laravel 4 site such that (1) major application groups' components (controllers/views/etc) are coupled together and (2) Laravel's supporting code outside of in my web server's document root. The default laravel home page loads fine, but I can't get a namespaced controller to route correctly. This is the relevant file structure:
/ [Project Root]
/laravel [full laravel install here]
composer.json
/app
/controllers
BaseController.php
/dev
/htdocs
index.php
/app
/PageTypes
/Home
/controllers
HomeController.php
/views
HomeView.blade.php
The default laravel landing page is loading fine. But when I tried setting up a controller with its own namespace, I keep getting the errors.
This is HomeController.php:
namespace PageTypes;
use Home\controllers;
class HomeController extends BaseController {
public function showWelcome()
{
return View::make('hello');
}
}
Here's routes.php:
<?php
Route::get('/', function()
{
return View::make('hello');
});
Route::get('/home', 'PageTypes\Home\controllers\HomeController#showWelcome' );
This setup yields the error: "Symfony \ Component \ Debug \ Exception \ FatalErrorException
Class 'PageTypes\BaseController' not found" Ok, laravel is finding HomeController.php at least.
Plenty of other SO responses told me to try changing BaseController to \BaseController. Making that one change and leaving everything else the same yielded the error "ReflectionException: Class PageTypes\Home\controllers\HomeController does not exist." What the?... >.<
I'm not understanding something at the intersection of namespaces, psr-0, and laravel's routing, any help would be REALLY appreciated.
Followup questions: (1) what steps could I have taken to have debugged this? NGINX's logs aren't really telling me anything other than what I see in the exception errors being thrown. (2) Has anyone come across a laravel seed on github that's laid out similarly? I'd love to have something to reference.
Here are my configuration settings:
// index.php
...
require __DIR__.'/../../laravel/bootstrap/autoload.php';
$app = require_once __DIR__.'/../../laravel/bootstrap/start.php';
...
// bootstrap/autoload.php
...
require __DIR__.'/../vendor/autoload.php';
...
// bootstrap/paths.php
...
'app' => __DIR__.'/../app',
'public' => __DIR__.'/../../dev/htdocs/',
'base' => __DIR__.'/..',
'storage' => __DIR__.'/../app/storage',
...
// compose.json
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"require": {
"laravel/framework": "4.0.*"
},
"autoload": {
"psr-0": {
"PageTypes": "../dev/htdocs/app"
},
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php"
]
},
"scripts": {
"post-install-cmd": [
"php artisan optimize"
],
"pre-update-cmd": [
"php artisan clear-compiled"
],
"post-update-cmd": [
"php artisan optimize"
],
"post-create-project-cmd": [
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
},
"minimum-stability": "dev"
}
class HomeController extends \BaseController {
Basically because you are in a namespace you need to resolve the BaseController in the global namespace (That's what the \ does).
You could also get away with having
use \BaseController;
class HomeController extends BaseController {
But since you are only going to be referring to BaseController once in the entire controller there's not much point.
The other potential problem is your namespacing which is what PageTypes\Home\controllers\HomeController is referring to. That's not actually the Pathname, thats the namespace name it's looking for (it just so happens that the autoloaders that follow PSR match the directory structure to the namespaces).
Try using
namespace PageTypes\Home;
instead of just PageTypes

Resources