I am try to run any php artisan commend in my project but i can't every time try i find this error als when i try to load
In ProviderRepository.php line 149:
Call to undefined method Illuminate\Support\Facades\Schema::isDeferred()
Script #php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1
i don't know what happen i define database in config file and also at AppServiceProvider as a following
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;//to define class schema
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* #return void
*/
public function boot()
{
Schema :: defaultStringLength(191); //add when php artisan migrate pass error after used defult auth
}
/**
* Register any application services.
*
* #return void
*/
public function register()
{
//
}
}
and i am use php and laravel version:
"require": {
"php": "^7.1.3",
"fideloper/proxy": "^4.0",
"laraform/laraform-laravel": "^1.2",
"laravel/framework": "5.7.*",
"laravel/tinker": "^1.0"
},
Related
I am using Laravel 8, and my application is hosted in AWS Elastic Beanstalk. All the routes (routes/web) work fine, but the routes in API (routes/api) show NOT FOUND. The routes API is working ok in the localhost, which is the problem in Elastic beanstalk or EC2 where it is hosted that does not let access to these API routes. Does anyone have any solution? The server's in Apache, pointing out /public.
RouteServiceProvider.php
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Facades\Route;
class RouteServiceProvider extends ServiceProvider
{
/**
* The path to the "home" route for your application.
*
* This is used by Laravel authentication to redirect users after login.
*
* #var string
*/
public const HOME = '/home';
/**
* The controller namespace for the application.
*
* When present, controller route declarations will automatically be prefixed with this namespace.
*
* #var string|null
*/
// protected $namespace = 'App\\Http\\Controllers';
/**
* Define your route model bindings, pattern filters, etc.
*
* #return void
*/
public function boot()
{
$this->configureRateLimiting();
$this->routes(function () {
Route::prefix('api')
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
Route::middleware('web')
->namespace($this->namespace)
->group(base_path('routes/web.php'));
});
}
/**
* Configure the rate limiters for the application.
*
* #return void
*/
protected function configureRateLimiting()
{
RateLimiter::for('api', function (Request $request) {
return Limit::perMinute(60)->by(optional($request->user())->id ?: $request->ip());
});
}
}
run the commands:
>> php artisan auth:clear-resets
>> php artisan cache:clear
>> php artisan config:clear
>> php artisan event:clear
>> php artisan optimize:clear
>> php artisan route:cache
>> php artisan view:clear
>> php artisan config:clear
>> php artisan view:clear
>> npm run dev
>> php artisan key:generate
>> php artisan optimize
I have implemented query cached in my application and my cache driver
is array. But I want to clear all the cached query after certain time.
How can I do so using CLI or in controller ?
php artisan cache:clear
and in controller:
Artisan::call('cache:clear');
You can use this artisan commands for clearing cache from your laravel project:
//---Remove Routes Cache
php artisan route:clear;
php artisan route:cache
//---Flush the application cache
php artisan cache:clear;
//---Remove the configuration cache file
php artisan config:cache;
php artisan config:clear;
//---Clearing View Cache
php artisan view:clear;
php artisan view:cache;
To learn more about cache please visit the following URL:
https://dev.to/kenfai/laravel-artisan-cache-commands-explained-41e1#:~:text=To%20clear%20your%20application%20cache,cache%3Aclear%20Application%20cache%20cleared!
Artisan::call(['cache:clear']);
will run the command php artisan cache:clear. If you want it to be done automatically, you could call that command in the scheduler.
app/Console/Kernel.php
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* #var array
*/
protected $commands = [
//
];
/**
* Define the application's command schedule.
*
* #param \Illuminate\Console\Scheduling\Schedule $schedule
* #return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('cache:clear')->weekly();
}
/**
* Register the commands for the application.
*
* #return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}
This will run automatically if you add this entry to your crontab.
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
More on running the scheduler
I have created a new laravel project with --auth, but HomeController hasn't been created. I have tried with composer require laravel/ui and php artisan ui vue --auth in an existing project and I encounter the same problem. Any solutions? I know I coould create it manually, but it is annoying. Thanks
The HomeController is not being created at the time of writing 29-Apr-2020
a quick workaround is to create it manually:
php artisan make:controller HomeController
and then fill it with the following code:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class HomeController extends Controller
{
/**
* Create a new controller instance.
*
* #return void
*/
public function __construct()
{
$this->middleware('auth');
}
/**
* Show the application dashboard.
*
* #return \Illuminate\Contracts\Support\Renderable
*/
public function index()
{
return view('home');
}
}
It was a bug that was fixed by the Laravel staff in Laravel UI version 2.0.3.
i installed Laravel, made new controller and new request.I added a test routes in the request file but whenever i try to access it from the browser via Apache WAMP server it through NotFoundHttpException(1/1)
i tried modifying the Apache httpd.conf file
AllowOverride ALL
Require all granted
i tried php artisan route:clear and route:cache
i tried to access the route through different URLs
public/home
public/index.php/home
not working
however localhost/public loads laravel welcome page just fine
i opened config/app.php file and made sure that the RouteServiceProvider is included in the providers for the app
i opened RouteServiceProvider and the $namespace = 'App\Http\Controllers'
but still when i type php artisan route:list i could not find them
i am trying for a day now can any one help
this is my request file
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class master extends FormRequest
{
Route::get('/home','mastercontroller#index');
Route::get('/lina','mastercontroller#index');
Route::get('/love','mastercontroller#index');
/**
* Determine if the user is authorized to make this request.
*
* #return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* #return array
*/
public function rules()
{
return [
//
];
}
}
and this is my controller file
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class mastercontroller extends Controller
{
public function index()
{
return view('index');
}
}
it should load the index view
When I install Pusher package, I got an error "Class 'Pusher' not found".
Claudio's diagnosis is correct, the namespace Pusher was added in version 3; but changing the Laravel files is not a recommended solution.
A better way is to create an alias in config/app.php. Under the 'aliases' key, add this to the array in the "Third Party Aliases" section:
'Pusher' => Pusher\Pusher::class,
(OP posted the following answer in the question. The underlying issue is that version 3 of pusher-php-server introduces a namespace and so now requires use Pusher\Pusher.)
Create this command:
namespace App\Console\Commands;
use Illuminate\Support\Facades\File;
use Illuminate\Console\Command;
class FixPusher extends Command
{
/**
* The name and signature of the console command.
*
* #var string
*/
protected $signature = 'fix:pusher';
/**
* The console command description.
*
* #var string
*/
protected $description = 'Fix Pusher namespace issue';
/**
* Create a new command instance.
*
* #return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* #return mixed
*/
public function handle()
{
$broadcastManagerPath = base_path('vendor/laravel/framework/src/Illuminate/Broadcasting/BroadcastManager.php');
$pusherBroadcasterPath = base_path('vendor/laravel/framework/src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php');
$contents = str_replace('use Pusher;', 'use Pusher\Pusher;', File::get($broadcastManagerPath));
File::put($broadcastManagerPath, $contents);
$contents = str_replace('use Pusher;', 'use Pusher\Pusher;', File::get($pusherBroadcasterPath));
File::put($pusherBroadcasterPath, $contents);
}
}
Then add "php artisan fix:pusher" to composer.json file:
"post-update-cmd": [
"php artisan fix:pusher",
"Illuminate\\Foundation\\ComposerScripts::postUpdate",
"php artisan optimize"
]
With the version 3 of Pusher I realized that there is changed the namespace for Pusher\Pusher. If configure by composer when set it out the .env, BROADCAST_DRIVER=pusher, it's showing that error. Checking out the log, you can find out where is the proble, located at this file:
'vendor/laravel/framework/src/Illuminate/Broadcasting/BroadcastManager.php"
. It's necessary change the references for Pusher\Pusher instead of Pusher like the image:
then find out the function PusherBroadCaster and change the reference Pusher for Pusher\Pusher.
vendor/laravel/framework/src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php
Use this command and install pusher. It worked for me in Laravel and PHP 8.0.8 perfectly without any additions of code changes.
composer require pusher/pusher-php-server
It's worth checking the version of Pusher used in composer.json. At this moment if you got stuck with implementing Pusher in Laravel 8 or 9 then your pusher-php-server version should be close to 7. At this moment the version of pusher is 7.1.0 (beta)* and therefore you should change composer.json entry to
"pusher/pusher-php-server": "^7.0",
Check this out: https://packagist.org/packages/pusher/pusher-php-server
Just go to vendor/laravel/framework/src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php
and change "Use Pusher" to "Use Pusher/Pusher";