My code is copyed from the website.
Excel::create('Filename', function($excel) {
// Set the title
$excel->setTitle('Our new awesome title');
// Chain the setters
$excel->setCreator('Maatwebsite')
->setCompany('Maatwebsite');
// Call them separately
$excel->setDescription('A demonstration to change the file properties');
})->download('xls');
I successfully download once.
However the other try is error.
The error Message is that.
Whoops, looks like something went wrong.
FatalErrorException in LaravelExcelWriter.php line 263:
Call to a member function getMergeCells() on a non-object
in LaravelExcelWriter.php line 263
• Write following in cmd
composer require Maatwebsite/excel
• after install /run upper composer........Maalwebsite/excel successfully check in composer.json that
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.2.*",
"laravelcollective/html": "5.2.*",
"Maatwebsite/excel": "^2.1"
},
• config/app.php/ in provides
Maatwebsite\Excel\ExcelServiceProvider::class,
• config/app.php/ in alias
'Excel' => Maatwebsite\Excel\Facades\Excel::class,
• php artisan vendor:publish
• php artisan make:controller ExcelController
• open excel then create first_name,last_name,sex,email,phone then store datas and save as .csv
• in controlller for import
use App\Customer;
use Input;
use DB;
use Excel;
class ExcelController extends Controller
{
//
public function getImport()
{
return view('excel.importCustomer');
}
public function postImport()
{
Excel::load(Input::file('customer'),function($reader){
$reader->each(function($sheet){
Customer::firstOrCreate($sheet->toArray());
});
});
}
}
• in routes for import
Route::get('/getImport','ExcelController#getImport');
Route::post('/postImport','ExcelController#postImport');
• In controller for export
public function getExport()
{
$export=Customer::all();
Excel::create('Export Data',function($excel) use ($export){
$excel->sheet('Sheet 1',function($sheet) use ($export){
$sheet->fromArray($export);
});
})->export('xlsx');
}
I know why the reason.
Because there is not any sheet in my case.
However the sheet is necessary.
Thank you.
Related
I want to add telescope into my laravel 8 app, but having in .env
APP_ENV=local
TELESCOPE_ENABLED=true
and reading at site :
https://laravel.com/docs/8.x/telescope
The Telescope dashboard may be accessed at the /telescope route. By default, you will only be able to access this dashboard in the local environment.
on url
http://local-tads.com/telescope
I got 404 error, where http://local-tads.com - is local hosting of my app
In app/Providers/AppServiceProvider.php file I added lines :
<?php
namespace App\Providers;
class AppServiceProvider extends ServiceProvider
...
if ($this->app->environment('local')) {
$this->app->register(\Laravel\Telescope\TelescopeServiceProvider::class);
\Event::listen(
[
TransactionBeginning::class,
],
function ($event) {
...
I have unmodified vendor/laravel/telescope/config/telescope.php file.
Have I to add route in routes/web.php and in which way ?
How to get access to telescope dashboard ?
UPDATED BLOCK :
I run both commands :
php artisan telescope:install
php artisan migrate
But I did not find config/telescope.php, so I copied it from /vendor/ subdirectory
Running command
php artisan route:list
has no any “telescope” entry.
In file app/Providers/AppServiceProvider.php I added lines with telescope :
<?php
namespace App\Providers;
use App\Library\Services\AdminCategoryCrud;
//use App\Providers\TelescopeServiceProvider;
use Illuminate\Database\Events\TransactionBeginning;
use Illuminate\Database\Events\TransactionCommitted;
use Illuminate\Database\Events\TransactionRolledBack;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Blade;
use Laravel\Telescope\IncomingEntry;
use Laravel\Telescope\Telescope;
use Laravel\Telescope\TelescopeServiceProvider;
class AppServiceProvider extends ServiceProvider
{
public function register()
{
if ($this->app->environment('local')) {
$this->app->register(\Laravel\Telescope\TelescopeServiceProvider::class);
$this->app->register(TelescopeServiceProvider::class);
}
Not sure if all is correct?
in env I have :
APP_ENV=local
TELESCOPE_ENABLED=true
and in composer.json I added line :
"extra": {
"laravel": {
"dont-discover": [
"laravel/telescope"
]
}
},
and updated composer
But http://local-tads.com/telescope - still raise 404 error...
Thanks in advance!
I have this problem but I attention Laravel Documentation I watch this code and run them:
telescope:install
, you should remove the
TelescopeServiceProvider
service provider registration from your application's
config/app.php
configuration file. Instead, manually register Telescope's service providers in the
register
method of your
App\Providers\AppServiceProvider
class.
A potential answer to your problem could be removing the telescope package from the dont-discover array. So your new extra section would be like this one:
"extra": {
"laravel": {
"dont-discover": []
}
}
Also, don't forget to dump your autoload by running composer dump-autoload in your project folder. I hope this helps you :D
For more information please check this issue on the github repository.
I'm creating my own Laravel package for the first time. I create a new project and require orchestra/testbench in the project. Things look okay and I'm able to run tests inside the package but I couldn't use Laravel Excel inside my package.
in composer.json I added
"extra": {
"laravel": {
"providers": [
"Maatwebsite\\Excel\\ExcelServiceProvider"
],
"aliases": {
"Excel": "Maatwebsite\\Excel\\Facades\\Excel",
}
}
},
"require-dev": {
"orchestra/testbench": "6.0",
"phpunit/phpunit": "^9.5",
"maatwebsite/excel": "^3.1"
}
And also ran composer dump-autoload, when I want to use Laravel Excel inside my package I tried
use Maatwebsite\Excel\Facades\Excel;
class TaxCalculation {
public function incomeTax(): float
{
$table = Excel::import(new TaxImport(), 'file.xls');
}
But got an error
Illuminate\Contracts\Container\BindingResolutionException: Target class [excel] does not exist.
D:\code\packages\thai_tax\vendor\laravel\framework\src\Illuminate\Container\Container.php:832
D:\code\packages\thai_tax\vendor\laravel\framework\src\Illuminate\Container\Container.php:712
D:\code\packages\thai_tax\vendor\laravel\framework\src\Illuminate\Foundation\Application.php:796
D:\code\packages\thai_tax\vendor\laravel\framework\src\Illuminate\Container\Container.php:651
D:\code\packages\thai_tax\vendor\laravel\framework\src\Illuminate\Foundation\Application.php:781
D:\code\packages\thai_tax\vendor\laravel\framework\src\Illuminate\Container\Container.php:1354
D:\code\packages\thai_tax\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php:198
D:\code\packages\thai_tax\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php:166
D:\code\packages\thai_tax\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php:255
D:\code\packages\thai_tax\src\Services\TaxCalculation.php:45
D:\code\packages\thai_tax\tests\Unit\CreateFacadeTest.php:26
Caused by
ReflectionException: Class excel does not exist
Excel does not seem to load. Is there any more steps I need to do to use it?
I've build a Laravel Rest API with Dingo\API following a tutorial. I've set this up as virtual host at http://site.test
Vhosts are set up in httpd.conf and /etc/hosts files.
But, when I go to http://site.test, it shows the full project directory. So I have to click into the /routes/api.php, but I get the following error:-
Uncaught Error: Call to undefined function app() in /Users/param/Desktop/api/routes/api.php
undefined function app() in /Users/param/Desktop/api/routes/api.php
I ran this during set up:
php artisan vendor:publish --provider="Dingo\Api\Provider\LaravelServiceProvider"
My composer.json file
"require": {
"php": ">=7.1.3",
"dingo/api": "^2.1",
"fideloper/proxy": "^4.0",
"laravel/framework": "5.8.*",
"laravel/tinker": "^1.0"
}
RouteServiceProvider.php file
protected function mapApiRoutes()
{
Route::prefix('api')
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
}
routes/api.php file
$api = app('Dingo\Api\Routing\Router');
$api->version('v1', function ($api) {
$api->get('/', function () {
return ['fruits'=> 'Delicious'];
});
});
.env file
API_PREFIX=api
API_DEBUG=true
Would love any help in the right direction -- I can't figure out why http://site.test/api return that error?
For anybody looking for a solution to this assuming your Virtual host is http://site.test
On your.env file put http://site.test as your API_URL environment variable and put site.test as your API_DOMAIN environment variable
When running the example code on the laravel docs php artisan make:request StoreBlogPostRequest to create a new validation controller, I get the following error
[RuntimeException]
Unable to detect application namespace.
I'm not sure what's wrong, I've done some searching, but nothing really explains this error. Any ideas?
In Laravel 5, an "application" is a collection of PHP files under a single namespace, stored in the folder app/
By default, and in most of the Laravel 5 sample code from the docs, this namespace is App\. For example, one controller in your application might look like this.
namespace App\Http\Controller;
class MyController
{
//...
}
When Laravel generates code (i.e. when you use the make:request command), it needs to know what this application namespace is (it's possible to change the namespace with the artisan app:name command). For some reason, in your system, Laravel 5 can't detect the namespace.
If you look at the section of Laravel 5 core code that detects the namespace
#File: vendor/laravel/framework/src/Illuminate/Console/AppNamespaceDetectorTrait.php
protected function getAppNamespace()
{
$composer = json_decode(file_get_contents(base_path().'/composer.json'), true);
foreach ((array) data_get($composer, 'autoload.psr-4') as $namespace => $path)
{
foreach ((array) $path as $pathChoice)
{
if (realpath(app_path()) == realpath(base_path().'/'.$pathChoice)) return $namespace;
}
}
throw new RuntimeException("Unable to detect application namespace.");
}
You'll see that Laravel detects the namespace by looking at your composer.json file, and looking for thefirst valid psr-4 namespace.
My guess is your composer.json file is missing the namespace
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/"
}
},
Add that back in, and you'll be good to go.
Usually, this error can be mapped to syntax issues or errors in composer.json file. Check for any trailing commas or Auto load issue. For e.g.
"require-dev": {
"barryvdh/laravel-debugbar": "^3.5",
"phpunit/phpunit": "^7.5",
},
This should be..
"require-dev": {
"barryvdh/laravel-debugbar": "^3.5",
"phpunit/phpunit": "^7.5"
},
See no trailing commas at the end of "phpunit/phpunit": "^7.5"
I have installed laravel/socialite in my project but I can't understand how to make it work...
I have this in my composer.json:
"require": {
"laravel/framework": "5.0.*",
"laravelcollective/html": "~5.0",
"laravel/socialite": "~2.0"
},
I have added in my config/app.php:
'Socialize' => 'Laravel\Socialite\SocialiteServiceProvider'
and:
'Laravel\Socialite\SocialiteServiceProvider',
Then:
composer dump-autoload
Added a new route:
Route::get('auth/facebook', 'Auth\AuthController#getFacebookLogin');
Add the new method:
/**
* #return mixed
*/
public function getFacebookLogin()
{
return \Socialize::with('facebook')->redirect();
}
But all I get is:
FatalErrorException in AuthController.php line 43: Call to undefined method Laravel\Socialite\SocialiteServiceProvider::with()
Where is the error?
You should add
'Socialize' => 'Laravel\Socialite\Facades\Socialite'
as an alias in your app.php.
It seems the Facade alias doesn't really work anymore for Socialite. I think the docs could use some love, in general, too (especially since I don't think it's supposed to be aliased as "socialize").
What I found to work was to alter your use statement to
use Laravel\Socialite\Contracts\Factory as Socialite;
and drop the alias entry altogether.