Mohammad Khazaee
2 years ago
9 changed files with 76 additions and 79 deletions
-
4app/Http/Controllers/FileController.php
-
4app/Http/Kernel.php
-
29app/Http/Middleware/BindCollectionModelMiddleware.php
-
60app/Http/Requests/FileStoreRequest.php
-
12app/Models/Collection.php
-
14app/Models/File.php
-
22app/Providers/RouteServiceProvider.php
-
1config/app.php
-
9routes/api.php
@ -0,0 +1,29 @@ |
|||
<?php |
|||
|
|||
namespace App\Http\Middleware; |
|||
|
|||
use App\Models\Collection; |
|||
use Closure; |
|||
use Illuminate\Http\Request; |
|||
|
|||
class BindCollectionModelMiddleware |
|||
{ |
|||
/** |
|||
* Handle an incoming request. |
|||
* |
|||
* @param \Illuminate\Http\Request $request |
|||
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next |
|||
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse |
|||
*/ |
|||
public function handle(Request $request, Closure $next) |
|||
{ |
|||
if ($request->route()->action['as'] == 'api.file.store') { |
|||
app()->bind('collection',function() use ($request) |
|||
{ |
|||
return Collection::where('name',$request->route('collections_name'))->get(); |
|||
}); |
|||
} |
|||
|
|||
return $next($request); |
|||
} |
|||
} |
@ -1,60 +0,0 @@ |
|||
<?php |
|||
|
|||
namespace App\Http\Requests; |
|||
|
|||
use App\Models\Collection; |
|||
|
|||
use Illuminate\Foundation\Http\FormRequest; |
|||
|
|||
class FileStoreRequest extends FormRequest |
|||
{ |
|||
|
|||
private $collection = null; |
|||
|
|||
public function __construct() |
|||
{ |
|||
|
|||
$this->collection = Collection::where('name',$this->collection_name)->get(); |
|||
} |
|||
|
|||
/** |
|||
* Determine if the user is authorized to make this request. |
|||
* |
|||
* @return bool |
|||
*/ |
|||
public function authorize() |
|||
{ |
|||
return true; |
|||
} |
|||
|
|||
private function getExts() |
|||
{ |
|||
return implode(",",$this->collection->exts); |
|||
} |
|||
|
|||
private function getMimeTypes() |
|||
{ |
|||
return implode(",",$this->collection->mimetypes); |
|||
} |
|||
|
|||
// private function getExt()
|
|||
// {
|
|||
// return implode(",",$this->collection->ext);
|
|||
// }
|
|||
|
|||
/** |
|||
* Get the validation rules that apply to the request. |
|||
* |
|||
* @return array<string, mixed> |
|||
*/ |
|||
public function rules() |
|||
{ |
|||
return [ |
|||
"ext" => ["mimes:" . $this->getExts], |
|||
"memetype" => ["mimetypes:" . $this->getMimeTypes], |
|||
"width"=> [''], |
|||
"height"=> [''], |
|||
"file_size"=> [''], |
|||
]; |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue