php artisan vendor:publish mervick/emojionearea - laravel

In installation no describe process publishing this package.
But I would like to setup it.
Laravel 5.6
composer require mervick/emojionearea ^3.0.0
and I need to copy from folder /vendor to /public/vendor using
php artisan vendor:publish
I created file /vendor/mervick/emojioneareaServiceProvider.php
and added lines:
public function boot()
{
$this->publishes(
[
__DIR__ . '/dist' =>
public_path('vendor/mervick/emojionearea/dist'),
],
'emojionearea'
);
}
also, I added lines to /config/app.php
//ServiceProviders
Mervick\EmojioneArea\EmojioneAreaServiceProvider::class,
//Aliases
'EmojioneArea'=> Mervick\EmojioneArea\EmojioneAreaServiceProvider::class,
and run command :
php artisan vendor:publish
also, I used the command:
php artisan vendor:publish --provider="Mervick\EmojioneArea\EmojioneAreaServiceProvider"
Any help.Thanks.

Please follow below steps i have tried moved files to public/vendor folder by updating below steps. Its works fine.
Service provider file.
<?php
namespace mervick\emojionearea;
use Illuminate\Support\ServiceProvider;
class EmojioneAreaServiceProvider extends ServiceProvider
{
/**
* Bootstrap services.
*
* #return void
*/
public function boot()
{
$this->publishes([
__DIR__.'/../dist' => base_path('public/vendor/dist'),
]);
}
}
In your root composer.json file add your vendor for identify the service provider.
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/",
"Mervick\\EmojioneArea\\": "vendor/mervick/emojionearea/src"
}
}
Like you said don't forgot to add the service provider in config/app.php
Mervick\EmojioneArea\EmojioneAreaServiceProvider::class,
If everything works fine for you. Please make it as correct answer.:-)

Related

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

Getting class does not exist error when running database seeder

I am creating a seeder in laravel 6.1 but I keep getting this error
Illuminate\Contracts\Container\BindingResolutionException : Target class [AdminsTableSeeder] does not exist.
I tried running composer dump-autoload and composer dumpautoload, it doesn't work for me.
here is my AdminsTableSeeder.php
use App\Models\Admin;
use Faker\Factory as Faker;
use Illuminate\Database\Seeder;
class AdminsTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* #return void
*/
public function run()
{
$faker = Faker::create();
Admin::create([
'name' => $faker->name,
'email' => 'admin#admin.com',
'password' => bcrypt('password'),
]);
}
}
and here is my DatabaseSeeder.php
<?php
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*
* #return void
*/
public function run()
{
$this->call(AdminsTableSeeder::class);
}
}
Make sure your AdminsTableSeeder.php file is in the same directory where you have your DatabaseSeeder.php file.
Run
composer dump-autoload
then try
php artisan db:seed
Optional.
class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*
* #return void
*/
public function run(){
$this->call('AdminsTableSeeder');
}
}
try with $this->call('AdminsTableSeeder'); like this.
In your case, move all seeder files from previous database/seeds directory to database/seeders folder & then run composer dump-autoload.
Remember, from laravel 8 seeders and factories are namespaced
To accommodate for these changes,
[1] - Add Database\Seeders namespace to your seeder classes.
namespace Database\Seeders;
[2] - Move all seeder files to database/seeders folder.
[3] - If you import any seeders classes in DatabaseSeeder file then remove all of them. (simply remove all lines that started with use Database\Seeders\... from DatabaseSeeder.php)
[4] - Finally run dump-autoload.
composer dump-autoload
You can now try a fresh migration with seed,
php artisan migrate:fresh --seed
For my case(I use Laravel 8), I solved my problem by modifying the RouteServiceProvider.php file in App/Providers/ path. I uncommented code on line 29.
protected $namespace = 'App\\Http\\Controllers';
It worked for me.
run
composer dump-autoload
then try
php artisan db:seed
For Laravel 8:
I have the same issue and I found a solution in Laravel doc and it's worked for me.
https://laravel.com/docs/8.x/upgrade#seeder-factory-namespaces
Update Composer:
"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}
}
Run:
composer dumpautoload
php artisan db:seed --force
Concerning my case, I used the latest Laravel 8 which is the latest version, I solved my problem by changing the RouteServiceProvider.php file in App/Providers/ path by uncommenting the code on line 29.
protected $namespace = 'App\Http\Controllers';
For Laravel ^7.0
If your using Laravel Eloquent
Example:
<?php
use App\Models\User;
use Illuminate\Database\Seeder;
class UsersTableSeeder extends Seeder
{
public function run()
{
$users = [
[
'id' => 1,
'name' => 'Admin',
'email' => 'admin#admin.com',
'password' => bcrypt('password'),
'remember_token' => null,
],
];
User::insert($users);
}
}
If your using Laravel Query Builder
Example:
<?php
//Do not use -> namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class UsersTableSeeder extends Seeder
{
public function run()
{
DB::table('users')->insert([
'name' => 'Admin',
'email' => 'admin#admin.com',
'password' => bcrypt('password'),
'remember_token' => null,
]);
}
}
In your DatabaseSeeder.php
<?php
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
public function run()
{
$this->call([
UsersTableSeeder::class,
]);
}
}
Seems like the controller name is case-sensitive in Laravel 8. So my suggestion is to double-check the controller name.
For instance:
in web.php avoid calling
UserAPIController
as
UserApiController
(API as api)
It may fix this error.
In your DatabaseSeeder.php, you can add the nameSpace for AdminsTableSeeder like -
use App\Models\Admin\AdminsTableSeeder;
Closing the current running serve before doing db:seeds

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 Controller Namespace

how i can change my controller namespace from
namespace App\Http\Controller\Folder\MyController
to
namespace Folder\MyController
im new using laravel 5.2
you can change psr-4 in your composer.json file.
"psr-4": {
"YourProject\\": "app/"
}
so, your namespace will be namespace YourProject/Http/Controller. don't forget to autoload your composer. I assume this is you are looking for.
This is baked in to 5.2 artisan commands;
php artisan app:name MyApp
think you'll need to run php artisan dump-autoload afterwards.
You need to add this in your controller:
namespace App\Http\Controllers\Folder;
use App\Http\Controllers\Controller;
and add this in your route,
Route::group(['namespace'=>'Folder'], function () {
// place your MyController route here;
});
Try this :
1) run php artisan app:name YourNamespace
2) rename your app folder to YourNamespace
3) in your bootstrap folder create a file called application.php
4) paste this in there
class Application extends Illuminate\Foundation\Application {
protected $appBasePath = 'app';
public function __construct($basePath = null)
{
$this->registerBaseBindings();
$this->registerBaseServiceProviders();
$this->registerCoreContainerAliases();
if ($basePath) $this->setBasePath($basePath);
}
public function setAppPath($path) {
// store the path in the class only
$this->appBasePath = $path;
// set the path in the container (using this class's path to reset it)
return app()->__set('path', $this->path());
}
/**
* Get the path to the application "app" directory.
*
* #return string
*/
public function path()
{
return $this->basePath.DIRECTORY_SEPARATOR.$this->appBasePath;
}
}
5) save the file and open app.php
6) and replace your application bootstrap with the following
// load our local application
require __DIR__.'/application.php';
// instaniate our application
$app = new \Application(
realpath(__DIR__.'/../')
);
// set the path to match the namespace
$app->setAppPath('YourNamespace');
7) Save your app.php and that's it
Hope this help you.

Laravel 5 getstream.io getUserFeed()

I'm trying to use getstream.io in my Laravel 5 application. I'm following the tutorial here, but got stuck on this one:
$feed = FeedManager::getUserFeed($user->id);
When I go to the FeedManager class, I couldn't find the getUserFeed() method. Here's how my FeedManager class look like:
<?php namespace GetStream\StreamLaravel\Facades;
use Illuminate\Support\Facades\Facade;
class FeedManager extends Facade {
/**
* Get the registered name of the component.
*
* #return string
*/
protected static function getFacadeAccessor() { return 'feed_manager'; }
}
I wonder if I did something wrong during installation. The tutorial said to run php artisan config:publish get-stream/stream-laravel, but I did php artisan vendor:publish get-stream/stream-laravel. The reason is because I got an error when running config:publish, so I used vendor:publish instead
The Stream-PHP-Example is now working in Laravel 5, take a look: https://github.com/GetStream/Stream-Example-PHP

Resources