vendredi 5 juin 2020

403 forbidden when i send PHP code into request to Laravel function

i have a problem in my Laravel function , i am creating a forum for web developers and all requests to the function works fine without no problem in any programming language but when i write PHP code in request which i send to the laravel function it's give me 403 forbidden i don't know why ?
this happen when the request include and if i make return $req->all(); at the top of the function which receive the request i get Error in the request 301
You can try it by yourself here https://mohamedatef-staging.space/ng-websquare/ in the page of New discussion https://mohamedatef-staging.space/ng-websquare/new-discussenter image description here

    public function new_discussion(Request $request){
    // return $request->all()['images'];
    $data_array = $request->all()['dataArray'];
    $data = json_decode($data_array, true);
    $validator = Validator::make($data, [
        'title' => 'required',
        'data' => 'required',
        'tags' => 'required',
    ],[
        'title.required' => 'missingTitle',
        'data.required' => 'missingData',
        'tags.required' => 'missingTags',
    ]); 
    if($validator->fails()){
        return response($validator->messages(), 200);
    }
    // $images_array = $request->all()['images'];
    // return $images_array;
    $urls = [];
    if(!empty($request->all()['images'])){
        $validator2 = Validator::make($request->all(), [
            'images' => 'required|array|min:1',
            'images.*' => 'image|mimes:jpeg,jpg,png|max:20000',
        ], [
            'images.*image' => 'image_file_error',
            'images.*mimes' => 'image_file_error',
            'images.*max' => 'image_file_max',
        ]);
        if($validator2->fails()){
            return response($validator2->messages(), 200);
        }
        $images = $request->all()['images'];
        foreach ($images as $image) {
            $count = 0 ; 
            $image_name = time() . '.' . $image->getClientOriginalName();
            $image->move(public_path('/images/forum'), $image_name);
            $image_url = '/images/forum/'.$image_name;
            $urls[] = $image_url;
            $count++;
        }
    }
    // }
    // return response(['urls' => $urls[0]]);
    // return response(['owner' => auth('members')->user()->id]);
    $forum_slug = preg_replace('~[^\pL\d]+~u', '-', $data['title']);
    $forum_slug2 = strtolower($forum_slug);
    $forum = new forum ; 
    $forum->ownerID = auth('members')->user()->id;
    $forum->title = $data['title'];
    $forum->slug = $forum_slug2;
    $forum->content = $data['data'];
    $forum->tags = $data['tags'];
    if(!empty($urls[0])){
        $forum->img1 = $urls[0];
    }
    if(!empty($urls[1])){
        $forum->img2 = $urls[1];
    }
    if(!empty($urls[2])){
        $forum->img3 = $urls[2];
    }
    $forum->views = 0;
    $forum->status = 0;
    $forum->comments = 0;
    $done = $forum->save();
    if($done){
        return response(['status' => 'done']);
    }
}


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2BtbSH9
via IFTTT

Aucun commentaire:

Enregistrer un commentaire