PHP code example of nabil12ful / store-data-requests
1. Go to this page and download the library: Download nabil12ful/store-data-requests library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
php artisan make:controller UserController -m User
protected $model = \App\Models\User::class;
protected $folderBlade = 'backend.user'; // View folder name OR path
protected $uploadPath = 'upload/user';
protected $columns = [
// table columns & fields name
'name',
'email',
];
protected $mediaColumns = [
// columns name have a media files like [Image, Pdf, Doc, etc...]
'image'
];
php artisan make:request UserStoreRequest
public function store(UserStoreRequest $request): RedirectResponse
{
StoreDataRequests::model($this->model)->make($request, $this->columns)->store($this->uploadPath);
}
protected $columns = [
// table columns & fields name with rules
'name' => 'ns & fields name has files with rules
'image' => '
public function store(Request $request)
{
$result = StoreDataRequests::model($this->model)->make($request, $this->columns)->storeValidated('upload/users');
if(isset($result->id))
{
toastr()->success('The data has been stored successfully', 'Success');
return redirect()->back();
}else{
return back()->withInput()->withErrors($result);
}
}
public function update($id, Request $request)
{
$result = StoreDataRequests::model($this->model)->make($request, $this->columns, $this->mediaColumns)->updateHasFilesValidate($id, $this->uploadPath);
if(!$result)
{
toastr()->success('The data has been updated successfully', 'Success');
return redirect()->back();
}else{
return back()->withInput()->withErrors($result);
}
}