Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel:Passport API和accept图像_Php_Laravel_Laravel Passport - Fatal编程技术网

Php Laravel:Passport API和accept图像

Php Laravel:Passport API和accept图像,php,laravel,laravel-passport,Php,Laravel,Laravel Passport,因此,我已经有了一个使用laravel passport的api 在我的controller中命名为AuthController.php Route::post('/login','Auth\Api\AuthController@login'); Route::middleware('auth:api')->group(function () { Some routes... Route::post('/activity_log','Auth\Api\AuthCo

因此,我已经有了一个使用laravel passport的
api

在我的
controller
中命名为
AuthController.php

Route::post('/login','Auth\Api\AuthController@login');

Route::middleware('auth:api')->group(function () {

     Some routes...

     Route::post('/activity_log','Auth\Api\AuthController@activity_log');
});
我有这个保存数据的工作代码

    public function activity_log(Request $request){

    $validatedData = $request->validate([
        'projCode'=>'required',
        'activity_desc'=>'required',
        'type'=>'required'
    ]);

    $tbl_projectlist = DB::connection('mysql')->select("SELECT * from tbl_projectlist WHERE proj_code = '".$request->projCode."'");

    if(empty($tbl_projectlist))
    {
        return response([
            "status"=>"bad",
            "message"=>"Invalid projCode doesn't exists."
        ]);
    }
    else if($request->type == "REPORT" || $request->type == "ISSUE")
    {
        $ActivityLog = new ActivityLog;
        $ActivityLog->projCode = $request->projCode;
        $ActivityLog->activity_desc = $request->activity_desc;
        $ActivityLog->type = $request->type;
        $ActivityLog->attachment = "/img/default-image.jpg";
        $ActivityLog->created_by_id = Auth::user()->company_id;
        $ActivityLog->created_by_name = Auth::user()->name;
        $ActivityLog->created_at = now();
        $ActivityLog->updated_at = now();
        $ActivityLog->save();

        return response([
            "status"=>"ok",
            "message"=>"Activity successfully submitted!"
        ]);
    }
    else
    {
        return response([
            "status"=>"bad",
            "message"=>"Invalid choose REPORT or ISSUE"
        ]);
    }

}
在我的
api.php

Route::post('/login','Auth\Api\AuthController@login');

Route::middleware('auth:api')->group(function () {

     Some routes...

     Route::post('/activity_log','Auth\Api\AuthController@activity_log');
});
到目前为止,我只存储img所在的图像
硬编码的文件路径

我试图做的是接受img文件并保存到我的文件夹中,然后将文件路径存储到我的数据库中

我正在使用postman来测试我的api



来自postman:使用POST方法,选择正文和表单数据,选择文件并使用图像作为键,然后从需要上载的值中选择文件

public function uploadTest(Request $request) {

    if(!$request->hasFile('image')) {
        return response()->json(['upload_file_not_found'], 400);
    }
    $file = $request->file('image');
    if(!$file->isValid()) {
        return response()->json(['invalid_file_upload'], 400);
    }
    $path = public_path() . '/uploads/images/store/';
    $file->move($path, $file->getClientOriginalName());
    return response()->json(compact('path'));
 }

你的前端框架是什么?移动应用程序将使用上传img的api。移动应用程序仍在规划过程中。我的api只运行后端应用程序将使用apiI建议使用表单作为操作链接与控制器将图像上载到后端服务器您的建议是什么意思<代码>http://192.168.0.35:905/api/activity_log
此链接只是一个后端链接。不像创建一个get路由(web.php),像get/upload\u图像链接到控制器,即:ImageController@upload,并制作一个表单以上载图像,这里是一个输入上载图像如果发送的文件不是图像,您如何验证该文件?将其用作validateur$this->validate($request,['file'=>'image | mimes:jpeg、png、jpg、gif、svg | max:2048',]);