Laravel class undefined after config:clear - laravel

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

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!

Export process work but no file downloaded [ Maatwebsite / Laravel-Excel ]

PHP version: 7.3.9
Laravel version: 5.8.30
Package version: 3.1
Description
I am trying to export excel file. I do all things in the documentation and the process work with no errors. but the excel file does not download.. I'm using Ubuntu OS.
UserExport.php
<?php
namespace App\Exports;
use App\User;
use Maatwebsite\Excel\Concerns\FromCollection;
class UsersExport implements FromCollection
{
/**
*/
public function collection()
{
return User::all();
}
}
ExportExcelController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Exports\UsersExport;
use Maatwebsite\Excel\Facades\Excel;
class ExportExcelController extends Controller
{
public function export()
{
return Excel::download(new UsersExport, 'users.xlsx');
}
}
I was seeing the same behavior. I got around it by clearing out all caches and recreating the config cache.
php artisan cache:clear
php artisan route:clear
php artisan view:clear
php artisan config:cache
I was using the package with inertia-vue and using an <a></a> in place of the <Link></Link> tag worked the trick

while retrieving data from WHMCS API I'm getting error as follows : InvalidArgumentException View [SME_Hosting] not found

I have created a controller and the coding in my controller file is as shown below
This is the controller code
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\View;
use DarthSoup\Whmcs\Facades\Whmcs;
use DarthSoup\Whmcs\WhmcsServiceProvider;
class GetProductController extends Controller
{
public function show(){
$products = Whmcs::GetProducts([
]);
return view('SME_Hosting',['products'=>$products]);
}}
This is my Route
Route::get('/SME_Hosting','GetProductController#show');
I'm getting same error even after clearing the cache by using the below functions:
php artisan config:cache
php artisan config:clear

Laravel 5.2 - ReflectionException Class laravel-fullcalendar does not exist

I am using the Fullcalendar package for Laravel 5.
I am experiencing this error:
ReflectionException in Container.php line 734:
Class laravel-fullcalendar does not exist
I have the Service Provider and the Facade in app.php.
This is my controller:
namespace App\Http\Controllers\Admin;
use App\Lesson;
use App\Http\Requests;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use MaddHatter\LaravelFullcalendar\Facades\Calendar;
class CalendarController extends Controller
{
public function index()
{
$calendar_events = Lesson::all();
return view('admin.calendar', ['calendar' => Calendar::addEvent($calendar_events)]);
}
}
I don't understand the reason of this error.
I tried to use \Calendar without the "use" line, MaddHatter\LaravelFullcalendar\Facades\Calendar::addEvent() directly and I tried several times composer dump-autoload.
I noticed that I started having the same problem with all the new installed packages.
I resolved in this way:
composer dump-autoload
php artisan cache:clear
php artisan config:clear

Class 'App\' not found on laravel 5.2

I want to add data to the database after a successful validation,but i get this error.'
FatalThrowableError in AboutController.php line 51:
Class 'App\About' not found.
My Controller
<?php
namespace App\Http\Controllers;
use App\About;
use Illuminate\Http\Request;
use App\Http\Requests;
class AboutController extends Controller
{
public function store(Request $request)
{
//
$about = $request->about;
$validation = \Validator::make($about, About::$rules);
if($validation->passes())
{
About::create($about);
return route('about/admin')->compact(about);
}
}
my Model
<?php
namespace App\Http\Controllers;
use Illuminate\Database\Eloquent\Model;
class About extends Model
{
//
protected $guarded = array('id');
protected $fillable = array('about');
public static $rules = array('about' => 'required|5');
}
location of controllers and Model:
App\Http\Controllers\AboutController
App\About
I have tried to run
php artisan cache:clear
php artisan clear-compiled
composer dump-autoload
I'm stuck can anyone tell me what is causing this?
As #webNeat said you should change the namespace that you are using in your Model.
Your Model About
<?php
namespace App\Http\Controllers;
use Illuminate\Database\Eloquent\Model;
class About extends Model
{
Controller
<?php
namespace App\Http\Controllers;
use App\About; // You have declared App\Http\Controllers in your Model
Model About Fixed
<?php
namespace App; // change to this namespace
use Illuminate\Database\Eloquent\Model;
class About extends Model
{
If you're a bit lost with Laravel or namespaces I strongly recommend you to use php artisan with each of its commands, and see and study what they do by reading all the code generated. For this case with:
php artisan make:model About
You will get a fresh new About model prepared for receive all your code with the correct namespace.
changing the namespace of your model to App should fix the issue.
<?php
namespace App; // <- here
use Illuminate\Database\Eloquent\Model;
class About extends Model
{

Resources