Nova 3 and Laravel 8
In RouteServiceProvider I added
Route::prefix('nova-api')
->middleware(['nova'])
->domain(config('nova.domain'))
->namespace('App\Http\Controllers\Nova')
->group(base_path('routes/nova-api.php'));
And the file content is
Route::delete('/{resource}/{resourceId}/field/{field}', 'FieldDestroyController#handle');
Route::delete('/testing', 'FieldDestroyController#handle');
After restarting project I see testing route, but not nova overwritten.
Is it possible to overwrite routes and how ?
Solution that works!
Create new ServiceProvider
php artisan make:provider NovaServiceProvider (or php artisan make:provider NovaRouteServiceProvider)
And place overwrite code .
In my case it is
<?php
namespace App\Providers;
use Illuminate\Support\Facades\Route;
use Laravel\Nova\NovaServiceProvider as ServiceProvider;
class NovaServiceProvider extends ServiceProvider
{
protected function registerRoutes()
{
parent::registerRoutes();
Route::prefix('nova-api')
->middleware(['nova'])
->domain(config('nova.domain'))
->namespace('App\Http\Controllers\Nova')
->group(base_path('routes/nova-api.php'));
}
}
Related
please help me, I'm learning and using Laravel 8.x . I don't know what is my error in this case.
...
vendor\laravel\framework\src\Illuminate\Container\Container.php:833
...
this is my controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class AdminController extends Controller
{
public function index(){
echo'admin';
}
}
and this is my web.php
<?php
use Illuminate\Support\Facades\Route;
Route::get('/admin','AdminController#index');
Since Laravel 8 default namespace App\Http\Controllers is not registered by default in RouteServiceProvider
So you need to use FQCN for the controller in the routes file other wise you will get the container binding resolution exception as you are getting
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\AdminController;
Route::get('/admin', [AdminController::class, 'index']);
This happens from Laravel 8, since the App\Http\Controllers namespace isn't registered by default. You can register it in the corresponding service provider:
# app/Providers/RouteserviceProvider.php
// Uncomment this line
protected $namespace ='App\\Http\\Controllers';
Is there a way to disable artisan commands from running at all?
For example, if I wanted to disable php artisan migrate:fresh from running, where would I go to remove/disable the command?
As far as I know, laravel does not have this feature by default. And this is still under laravel ideas.
I also had this problem before and could not find a solution, I am not sure why you want to disable a command. But my case was that in the production environment I never want to run php artisan migrate:fresh. So what I end up with is to override the default command.
For example, in the routes/console.php file:
if ('production' === App::environment()) {
Artisan::command('migrate:fresh', function () {
$this->comment('You are not allowed to do this in production!');
})->describe('Override default command in production.');
}
So, when you are in production, php artisan migrate:fresh will do nothing. You can change the condition based on your requirement, my example is just an idea of how you can override a laravel default command based on some variables in the .env file.
You can do a lot of things here as well, I am not sure why you want to disable the command, so this is the best I can help.
Create a command like the following
<?php
namespace App\Console\Commands\Utils;
use Illuminate\Console\Command;
use Illuminate\Console\Events\CommandStarting;
class PreCommand extends Command
{
protected $signature = 'precommand';
public function handle(CommandStarting $event) {
if (app()->environment(['production'])) {
logger('Trying to fresh database in production');
if ($event->command == 'migrate:fresh') {
$this->output = $event->output;
$this->info('You can not fresh database in the production');
die();
}
}
}
}
And register it in your EventServiceProvider's boot method
<?php
namespace App\Providers;
use App\Console\Commands\Utils\PreCommand;
use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
use Illuminate\Console\Events\CommandStarting;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Event;
class EventServiceProvider extends ServiceProvider
{
/**
* Register any events for your application.
*
* #return void
*/
public function boot() {
Event::listen(CommandStarting::class, PreCommand::class);
}
}
I created a new Laravel controller named "StoriesController" using the CLI:
php artisan make:controller StoriesController
When I open app/Http/Controllers/StoriesController.php, I see:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class StoriesController extends Controller
{
//
}
My question is about the line:
class StoriesController extends Controller
Where is the "Controller" script located? Which directory?
{your-project]/app/http/controllers/{StoriesController}
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
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