mardi 3 septembre 2019

We are craving with conditional branch

My if sentence is very difficult to read
ProjectController.php

public function index(Request $request)
{
    $cats = Category::all();
    $users = User::all();
    if(!empty($request->project_name && $request->requester && $request->user_name && $request->status && $request->requester_tell))
    {
        $view = Project::where('project_name', 'like', '%'. $request->project_name .'%')->where('project_name', 'like', '%'. $request->requester .'%')->get();
    } if(!empty($request->project_name && $request->requester && $request->user_name && $request->status))
    {   
        $view = Project::where('project_name', 'like', '%'. $request->project_name .'%')->paginate(10)->get();
    }else if(!empty($request->project_name && $request->requester && $request->user_name))
    {
        $view = Project::where('requester', 'like', '%'. $request->requester .'%')->paginate(10)->get();
    } else if(!empty($request->project_name && $request->requester))
    {
        $view = Project::where('user_name', 'like', '%'. $request->user_name .'%')->paginate(10)->get();
    } else if(!empty($request->project_name))
    {
        $view = Project::where('status', 'like', '%'. $request->status .'%')->paginate(10)->get();
    } else if(!empty($request->project_name || $request->requester || $request->user_name || $request->status || $request->requester_tell))
    {
        $view = Project::where('requester_tell', 'like', '%'. $request->requester_tell .'%')->paginate(10)->get();
    } else if(!empty($request->requester && $request->user_name))
    {

    } else if(!empty($request->status && $request->requester_tell))
    {

    } else if(!empty($request->requester && $request->requester_tell))
    {

    } else {
    };

I've written so far, but I want to know if there is a better way to write I want to pull data that matches the search conditions from the DB



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

Aucun commentaire:

Enregistrer un commentaire