I've seen several threads with this error but not of them are the right fix for me.
Getting this error when I try to delete an entry in my Laravel Backpack CRUD tables:
InvalidArgumentException in FilesystemManager.php line 121: Driver []
is not supported.
Guessing it has something to do with my filesystems.php
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
's3' => [
'driver' => 's3',
'key' => env('AWS_KEY'),
'secret' => env('AWS_SECRET'),
'region' => env('AWS_REGION'),
'bucket' => env('AWS_BUCKET'),
],
'uploads' => [
'driver' => 'local',
'root' => public_path('uploads'),
],
...
'hero' => [
'driver' => 'local',
'root' => storage_path('app/content/img/heroes/'),
],
...
Or my Model
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Backpack\CRUD\CrudTrait;
use Glide;
class HeroImages extends Model {
use CrudTrait;
protected $primaryKey = 'id';
protected $fillable = [
'hero_id',
'image',
'title',
'sub_title',
'link_label',
'link_value',
'order',
'status',
];
protected $table = "hero_images";
/*
* ADMIN: Store image on server
*/
public function setImageAttribute($value)
{
$attribute_name = "image";
$disk = "hero";
$destination_path = "";
// if the image was erased
if ($value==null) {
// delete the image from disk
\Storage::disk($disk)->delete($this->{$attribute_name});
// set null in the database column
$this->attributes[$attribute_name] = null;
}
// if a base64 was sent, store it in the db
if (starts_with($value, 'data:image'))
{
// 0. Make the image
$image = \Image::make($value);
// 1. Generate a filename.
$filename = md5($value.time()).'.jpg';
// 2. Store the image on disk.
\Storage::disk($disk)->put($destination_path.'/'.$filename, $image->stream());
// 3. Save the path to the database
$this->attributes[$attribute_name] = $destination_path.'/'.$filename;
}
}
/*
* ADMIN: Delete image from database (https://laravel-backpack.readme.io/v3.0/docs/crud-fields#section-image)
*/
public static function boot()
{
parent::boot();
static::deleting(function($obj) {
\Storage::disk('public_folder')->delete($obj->image);
});
}
}
Nevermind, I just saw the error when I posted my code. In
Storage::disk('public_folder')->delete($obj->image);
public_folder was not the correct attribute, I needed the disk name for the columns I was working with. In this case 'hero'
Related
I've recently installed this package and configured everything with guide but some how it's not working!
By it's not working I mean it's not adding anything to database. I really don't know what is wrong with my configs but I've checked everything with guide 3 times and everything is correct but... I don't know
config/audit.php:
<?php
return [
'enabled' => env('AUDITING_ENABLED', true),
'implementation' => OwenIt\Auditing\Models\Audit::class,
'user' => [
'morph_prefix' => 'user',
'guards' => [
'web',
'api',
],
],
'resolver' => [
'user' => OwenIt\Auditing\Resolvers\UserResolver::class,
'ip_address' => OwenIt\Auditing\Resolvers\IpAddressResolver::class,
'user_agent' => OwenIt\Auditing\Resolvers\UserAgentResolver::class,
'url' => OwenIt\Auditing\Resolvers\UrlResolver::class,
],
'events' => [
'created',
'updated',
'deleted',
'restored',
'gold_mailed' => 'goldMailed',
'invited' => 'clientInvited',
],
'strict' => false,
'timestamps' => false,
'threshold' => 0,
'driver' => 'session',
'drivers' => [
'eloquent' => [
'table' => 'audits',
'connection' => null,
],
],
'console' => true,
];
My model that I want to audit:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use OwenIt\Auditing\Contracts\Auditable;
use App\Models\Expansion;
use App\Models\Audit;
class Setting extends Model implements Auditable
{
protected $table = 'settings';
use \OwenIt\Auditing\Auditable;
protected $fillable = [
'expansion_id', 'season', 'advertiser_app', 'pvp_app', 'raid_app', 'version'
];
protected $auditInclude = [
'expansion_id', 'season', 'advertiser_app', 'pvp_app', 'raid_app', 'version'
];
public function Expansion()
{
return $this->hasOne(Expansion::class, 'id', 'expansion_id');
}
}
web.php:
Route::post('/setting' , 'Admin\SuperAdminController#saveSetting')->middleware('superadmin')->name('admin_save_setting');
Controller:
public function saveSetting(Request $request)
{
$sql = Setting::where('id', 1)->update([
'expansion_id' => $request['expansion_id'],
'season' => $request['season'],
'advertiser_app' => $request['advertiser_app'],
'pvp_app' => $request['pvp_app'],
'raid_app' => $request['raid_app'],
'version' => $request['version']
]);
if ($sql) {
toastr()->success('Settings successfully updated.');
return redirect()->back();
}
toastr()->error('Something went wrong!');
return redirect()->back();
}
I don't know what infos do you need but I think this is enough
I think my problem is with "driver" in config file , I don't know if that's correct or not
[UPDATED]
Based on the controller code you showed, it didn't work because your code is being called using Builder style, and the package only works when it is called using Eloquent style.
Documentation link
So, maybe you need to change your code to:
$setting = Setting::where('id', 1)->firstOrFail();
$setting->update([
'expansion_id' => $request['expansion_id'],
'season' => $request['season'],
'advertiser_app' => $request['advertiser_app'],
'pvp_app' => $request['pvp_app'],
'raid_app' => $request['raid_app'],
'version' => $request['version']
]);
now I have another problem -_-
this is my controller:
$sql = Raid::findOrFail($request['id']);
$sql = $sql->update($request->all());
I have a array in my table , after update value will be like this:
"{\"Plate\":0,\"Cloth\":0,\"Mail\":0,\"Leather\":0}"
but it should be:
{"Plate":"0","Cloth":"0","Mail":"0","Leather":"0"}
so I will get an error
before this , I was updating like this and it was ok:
$sql = Raid::where('id', $request['id'])->update($request->all());
and this is my mode (traders and class_traders is fields that I have problem with):
use SoftDeletes;
use \OwenIt\Auditing\Auditable;
protected $table = 'raid';
protected $dates = ['date_and_time','deleted_at'];
protected $fillable = [
'admin_id', '....
];
protected $casts = [
'bosses' => 'array',
'traders' => 'array',
'class_traders' => 'array',
'boosters' => 'array',
];
I still a newbie in Laravel. Please help me to solve my issue. I stuck on to prevent the file from the public. I trying to make the file access from public to private in Laravel 7.
I put all of the links in the auth it made all of the links required access before using it. I was tried to access some links to create a record. I can't do it and the system required the auth but when I use the URL http://127.0.0.1:8000/storage/actions/filename.something without log-in to access the image file. I still can see the file.
This is my route
Route::group(['prefix' => 'admin', 'middleware'=> ['auth', 'administrator']], function () {
//Action
Route::get('/addAction', 'admin\ActionController#create');
Route::get('/deleteAction/{id}', 'admin\ActionController#delete');
Route::get('editAction/{id}', 'admin\ActionController#edit');
Route::post('/addAction', 'admin\ActionController#store');
Route::post('/updateAction/{id}', 'admin\ActionController#update');
Route::get('/allAction', 'admin\ActionController#index');
Route::get('/delete/actionImage/{id}', 'admin\ActionController#deleteimages');
});
This is the controller that I use to store the data to the database and the image to the file path.
public function index(){
return view('admin.allAction')
->with('actions',Action::all())
->with('challenges',Challenge::all())
->with('users',User::all())
->with('status',Status::all())
->with('images',Images::all());
}
public function create(){
$users = DB::table('users')
->where('role','2')
->get();
return view('admin.addAction')
->with('users', $users)
->with('status',Status::all());
public function store(Request $request){
$request->validate([
'name' => 'required|string|max:188',
'objective' => 'string|max:888',
'images' => 'required',
'images.*' => 'file|image|mimes:jpeg,png,jpg|max:8000',
]);
// Insert Data to Table
$action=new Action();
$action->name=$request->name;
$action->objective=$request->objective;
$action->status_id=$request->status_id;
$action->owner_id=$request->owner_id;
$action->challenge_id=$request->challenge_id;
/*dd($action);*/
$action->save();
if ($request->hasfile('images')) {
$images = $request->file('images');
foreach($images as $image) {
$name = time().'-'.$image->getClientOriginalName();
$name = str_replace(' ','-',$name);
/*$path =*/ $image->storeAs('actions', $name, 'public');
Images::insert([ /*OrUpdate*/
'name' => $name,
'action_id' => $action->id,
]);
}
}
Session()->flash("success", "Success!");
return redirect('/admin/addAction');
My filesystem.php
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
'permissions' => [
'file' => [
'public' => 0664,
'private' => 0600,
],
'dir' => [
'public' => 0775,
'private' => 0700,
],
],
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
'url' => env('AWS_URL'),
],
],
I never do private file before I don't know how to do it. I tried to search how to on the internet but I still can't make it possible.
Thank you for all of the comments in advance and sorry for my English.
iam using a laravel site and in my file i have a directory in path
/var/www/site/admin.site.com/public/storage/salescall
i need to upload a file to this salescall folder i have used the following code.
$filenameWithExt = $request->file('sales_call')->getClientOriginalName();
$filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);
$extension = $request->file('sales_call')->getClientOriginalExtension();
$filenameToStore = $filename . '-' . time() . '.' . $extension;
$request->file('sales_call')
->storeAs('', $filenameToStore, 'sales');
and my filesystems.php is as follows
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
's3' => [
'driver' => 's3',
'key' => env('AWS_KEY'),
'secret' => env('AWS_SECRET'),
'region' => env('AWS_REGION'),
'bucket' => env('AWS_BUCKET'),
],
'sales' => [
'driver' => 'local',
'root' => public_path('salescall'),
'visibility' => 'public',
],
],
file is not uploaded to folder.please help me to solve this. Thank you in advance.
You can easily do this:
$request->file('sales_call')-> storeAs('salescall/',$filenameToStore);
FOR BETTER UNDERSTANDING, SEE BELOW
The configuration of your filesystem seems to be incorrect.
Use the below sample as a guide and I hope it helps you.
If you use this code, it will upload your file in storage/app folder
Storage::disk('local')->put('file.txt', 'Contents');
Now, if you need to change the directory and store into the storage folder directly, you need to change something in the filesystems.php file.
Go to config/filesystems.php file and change the following code-
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
Here, this line of code 'root' => storage_path('app'), responsible to define where to store. You just adjust according to your demands.
Alternatively, In your controller, You could do something like this:
<?php
namespace App\Http\Controllers\Api;
use App\User;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Storage;
class UserAvatarController extends Controller
{
/**
* Handle the incoming request.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function __invoke(Request $request)
{
$request->validate([
'avatar'=> ['required','max:200']
]);
$user = User::findOrFail(auth()->user()->id);
// Handle file Upload
if($request->hasFile('avatar')){
//Storage::delete('/public/avatars/'.$user->avatar);
// Get filename with the extension
$filenameWithExt = $request->file('avatar')->getClientOriginalName();
//Get just filename
$filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);
// Get just ext
$extension = $request->file('avatar')->getClientOriginalExtension();
// Filename to store
$fileNameToStore = $filename.'_'.time().'.'.$extension;
// Upload Image
$path = $request->file('avatar')->storeAs('public/avatars',$fileNameToStore);
$user->avatar = $fileNameToStore ;
$user->save();
}
return $user;
}
}
But in your own case, I believe:
In your config, set the root key to storage_path('salescall')
Yours should be $path = $request->file('sales_call')->storeAs('public/salescall',$fileNameToStore);
Just let me know if this works.. Cheers!
You have to use like this
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
'permissions' => [
'file' => [
'public' => 0664,
'private' => 0600,
],
'dir' => [
'public' => 0775,
'private' => 0700,
],
],
],
$request->file('sales_call')-> storeAs('salescall/',$filenameToStore);
Hi i am trying to link google drive api to the laravel system for what i have used google drive api in laravel and configured the filesystem and env setting. But when executed it returns DISK not configured error.
Tried solution of clearing config cache and dump-autoload still the isuue persist same.
filesystem.php
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
'url' => env('AWS_URL'),
],
'google-drive' => [
'driver' => 'google',
'clientId' => env('GOOGLE_DRIVE_CLIENT_ID'),
'clientSecret' => env('GOOGLE_DRIVE_CLIENT_SECRET'),
'refreshToken' => env('GOOGLE_DRIVE_REFRESH_TOKEN'),
'folderId' => env('GOOGLE_DRIVE_FOLDER_ID'),
],
],
googledriveserviceprovider.php
public function boot()
{
Storage::extend('google-drive', function($app, $config) {
$client = new \Google_Client();
$client->setClientId($config['clientId']);
$client->setClientSecret($config['clientSecret']);
$client->refreshToken($config['refreshToken']);
$client->fetchAccessTokenWithRefreshToken($config['refreshToken']);
$service = new \Google_Service_Drive($client);
$adapter = new \Hypweb\Flysystem\GoogleDrive\GoogleDriveAdapter($service, $config['folderId']);
return new \League\Flysystem\Filesystem($adapter);
});
}
Route to put file.
Route::get('put', function() {
Storage::disk('google-drive')->put('test.txt', 'Hello World');
return 'File was saved to Google Drive';
});
Any help is deeply appreciated.
I think this line:
Storage::extend('google-drive', function($app, $config) {
should just be
Storage::extend('google', function($app, $config) {
I think this useful for you
filesystem.php
'disks' => [
'google' => [
'driver' => 'google',
'clientId' => env('GOOGLE_DRIVE_CLIENT_ID'),
'clientSecret' => env('GOOGLE_DRIVE_CLIENT_SECRET'),
'refreshToken' => env('GOOGLE_DRIVE_REFRESH_TOKEN'),
'folderId' => env('GOOGLE_DRIVE_FOLDER_ID'),
],
],
googledriveserviceprovider.php
public function boot()
{
Storage::extend('google', function($app, $config) {
$client = new \Google_Client();
$client->setClientId($config['clientId']);
$client->setClientSecret($config['clientSecret']);
$client->refreshToken($config['refreshToken']);
$client->fetchAccessTokenWithRefreshToken($config['refreshToken']);
$service = new \Google_Service_Drive($client);
$adapter = new \Hypweb\Flysystem\GoogleDrive\GoogleDriveAdapter($service, $config['folderId']);
return new \League\Flysystem\Filesystem($adapter);
});
}
Route file
Route::get('put', function() {
Storage::disk('google')->put('test.txt', 'Hello World');
return 'File was saved to Google Drive';
});
I'm using image field in laravel backpack 4.0 and it uploads the images without any problems. When I delete the image by using the delete button, it deletes the register (E.N. Probably means "it deletes the image from the database"), but not the image file from my local folder. I've checked the answer from backpack for laravel deleting image , but it did not help to fix my issue.
My config/filesystem:
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
'url' => env('AWS_URL'),
],
],
My Model code:
public function setImageAttribute($value)
{
$attribute_name = "image";
$disk = config('backpack.base.root_disk_name'); // or use your own disk, defined in config/filesystems.php
$destination_path = env('FOLDER_PUBLIC')."/uploads/medias"; // path relative to the disk above
// if the image was erased
if ($value==null) {
// delete the image from disk
\Storage::disk($disk)->delete($this->{$attribute_name});
// set null in the database column
$this->attributes[$attribute_name] = null;
}
// if a base64 was sent, store it in the db
if (starts_with($value, 'data:image'))
{
// 0. Make the image
$image = \Image::make($value)->encode('jpg', 90);
// 1. Generate a filename.
$filename = rand ( 10000 , 99999 ).'-'.strtolower(trim(preg_replace('/[\s-]+/', '-', preg_replace('/[^A-Za-z0-9-]+/', '-', preg_replace('/[&]/', 'and', preg_replace('/[\']/', '', iconv('UTF-8', 'ASCII//TRANSLIT', $this->title))))), '-')).'.jpg';
// 2. Store the image on disk.
\Storage::disk($disk)->put($destination_path.'/'.$filename, $image->stream());
// 3. Save the public path to the database
// but first, remove "public/" from the path, since we're pointing to it from the root folder
// that way, what gets saved in the database is the user-accesible URL
$public_destination_path = Str::replaceFirst(env('FOLDER_PUBLIC').'/', '', $destination_path);
$this->attributes[$attribute_name] = $public_destination_path.'/'.$filename;
}
}
public static function boot()
{
parent::boot();
static::deleting(function($obj) {
\Storage::disk('public')->delete($obj->image);
});
}
I have tried to change:
\Storage::disk('public')->delete($obj->image);
With:
\Storage::disk(config('backpack.base.root_disk_name'))->delete($obj->image);
But it is not working either,
Can anyone help me?
Sorry for my english
You're on the right track. Looks like something is misconfigured if code in boot() doesn't affect any changes. My guess is that that the $obj->image path to the file you're trying to delete is NOT the exact path to the file. You might need to add the destination folder there too.
public static function boot()
{
parent::boot();
static::deleting(function($obj) {
$disk = config('backpack.base.root_disk_name');
$destination_path = env('FOLDER_PUBLIC')."/uploads/medias";
\Storage::disk($disk)->delete($destination_path.'/'.$this->image);
});
}
If this works, to further improve the code, I recommend you turn the $disk and $destination_path variables into properties on the PHP class itself (the Laravel model). That way, you only define them in one place, and you can then use them in both methods, with something like $this->imageDisk and $this->imagePath.
Thanks for your reply, At the end I have fixed it, making this change:
public static function boot()
{
parent::boot();
static::deleting(function($obj) {
\Storage::disk('uploads')->delete($obj->image);
});
}
And in config/filesystem:
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
'url' => env('AWS_URL'),
],
'uploads' => [
'driver' => 'local',
/* 'root' => base_path().'/web/storage',*/
'root' => base_path().'/'.env('FOLDER_PUBLIC'),
],
],
Regards