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

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

Related

Nova route overwriting

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'));
}
}

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

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.5 Package Commands Won't Register

I have a package for Laravel 5.5 and in the CommandsServiceProvider boot() method, I have:
if($this->app->runningInConsole()){
$this->commands([
MyCommandClass:class,
]);
}
Then, my MyCommandClass looks like:
<?php
namespace Testing\Commands;
use Illuminate\Console\Command;
class MyCommandClass extends Command
{
protected $signature = "execute:test";
protected $description = "Description of the command";
public function __construct()
{
parent::__construct();
}
public function handle()
{
$this->info('Command Executed');
}
}
The issue is that Artisan does not list the command when I run php artisan and when I try to run the command with php artisan execute:test it tells me the command is not defined.
What am I missing here? I followed the documentation for registering package commands in Laravel 5.5
It would appear that the Auto discovery only works when pulling a package from a Git Repo via Composer. When developing a package, the composer files within the package do not seem to auto load.

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

Resources