mardi 22 septembre 2020

Laravel Multiple Select Old Value

i'm added multiple select box using bootstrap-select in create form everything goes very well but I've a problem in edit form .

I tried many way to get the old selected value but nothing works

Blade:

                                        <select class="selectpicker" name="students[]" data-style="select-with-transition" data-live-search="true" multiple title="Choose City" data-size="7">
                                        <option disabled> Multiple Options</option>
                                        @foreach($students as $student)
                                            <option value="" > </option>
                                        @endforeach
                                    </select>

Edit function:

 public function edit(Course $course)
{
    $students=Student::all();
    return view('course.edit',compact('course','students'));
}

Store Function:

public function store(Request $request)
{
    $request->validate([
        'name' => 'required',
    ]);
    $course = new Course;
    $course->name = $request->name;
    $course->teacher_id = $request->teacher_id;

    $course->save();
    $course->students()->sync($request->students);

    return redirect()->route('courses.index')
        ->with('success','Course created successfully.');
}

any idea to do this ??



via Chebli Mohamed

Missing required parameters for [Route: claim_card] [URI: admin/claim_card/{giftcard_id}/{layout_id}/{user_id}/{color_id}]. - Laravel

I am new to laravel and when created a route, this error is displayed. I am passing complete parameters and can't locate the error.

Here's the route:

Route::get('/admin/claim_card/{giftcard_id}/{layout_id}/{user_id}/{color_id}' , 'UserController@claim_card')->name('claim_card');

Here's the function:

public function claim_card($giftcard_id , $layout_id , $user_id , $color_id)
{
    $card = giftcard_codes::where([['is_active', '=' , 1], ['giftcard_id', '=' ,$giftcard_id], ['layout_id', '=' ,$layout_id]])->first();
    if ($card) {
        $user = User::where('id', $user_id)->first();
        $lay = point_prizes::where('id', $layout_id)->first();
        if ($user->points >= $lay->points) {
            $us['points'] = $user->points - $lay->points;
            $c['is_active'] = 0;
            $co['color_id'] = $color_id;
            $co['is_pending'] = 2;

            cliaim_prizes_transactions::where([['user_id' , $user_id] , ['giftcard_id' , $giftcard_id] , ['layout_id' , $layout_id]])->first()->update($co);

                    $al = new user_alerts();
                    $al->user_id = $user_id;
                    $al->alert = 'Successfully Claimed Giftcard';
                    $al->alert_main = $card->code;
                    $al->save();

                    redeem__requests::where([['giftcard_id' , $giftcard_id] , ['layout' , $layout_id] , ['user_id' , $user_id] , ['is_active' , 1]])->first()->update($c);
                    giftcard_codes::where([['is_active', 1], ['giftcard_id', $giftcard_id], ['layout_id', $layout_id]])->orderby('id', 'DESC')->first()->update($c);
                    return view('admin.redeem_requests' , ['data' => redeem__requests::where('is_active' , 1)->get() , 'alert' => 'Giftcard Given Successfully']);
        }
    }
    else {
        return view('admin.redeem_requests' , ['data' => redeem__requests::where('is_active' , 1)->get() , 'alert' => 'No Code Exists']);
    }
}

Here's the view(where I am passing these):

<a href="">

Any help would be appreciated.



via Chebli Mohamed

Searching for UTF-8 channels without UTF-8 letters in query

What is the best way to get non-utf8 results when slug contains UTF8 letters? (For example: When I type the slug "Zaidimai", select all from the database where like "Žaidimai" and "Zaidimai").

Current code:

$results = DB::table('channels') -> where([['name', 'like', '%' . $slug . '%'], ['status', '=', 'OK']]) -> orWhere([['slug', 'like', '%' . $slug . '%'], ['status', '=', 'OK']]) -> limit(3) -> get();

It works fine, but when I try to search for a channel by entering "Zaidimai" in the search bar, it doesn't show the channel I want (Žaidimai).



via Chebli Mohamed

lundi 21 septembre 2020

get correct data from array

i am trying to decode array. this is my array

array:4 [▼
  "_token" => "tgPAddbrf3hI5tBIQIGyFYe9Y5RpwCj3rpZG5uVf"
  "resident_id" => array:4 [▼
    117 => "117"
    114 => "114"
    116 => "116"
    118 => "118"
  ]
  "available" => array:1 [▼
    116 => "2020-09-22"
  ]
  "out_of_community" => array:1 [▼
    118 => "2020-09-22"
  ]
]

i am using foeach to get answer like

resident_id  available    out_of_community
116         "2020-09-22"  null
118           null        "2020-09-22"

is it possible from foreach. my code for it

foreach ($data as $key => $value) {
            $data['resident_id'] = $key;
            
            # code...
        }


via Chebli Mohamed

Laravel 5.7.5 API Request Json

I am using laravel API Authentication it is authenticating with api_token successfully as form-data. When I pass a data as Content_Type application/json. I am not receiving the Json data it shows empty array. How do I receive a JSON Request in the API? enter image description here

    public function create_invoice(Request $request) {       
    
    $data = $request->json()->all();
    }


via Chebli Mohamed

Laravel DB:raw with Union

I have the following querys which I need to unoin them but I'm getting the following error:

"message": "Method Illuminate\Support\Collection::getBindings does not exist."

The idea is that first query returns records grouped by month and the last query to union to first one, has the total values for each column grouped per month.

This is my expected output which is working correct the query in mysql:

enter image description here

SELECT USERS.ID AS ID, PROPERTIES.PROP_TYPE AS TIPO
,SUM(IF(MONTH(PROPERTIES.created_at) = 1, PROPERTIES.PROP_EXCLUSIVE = 'Exclusiva',0)) as ENE
,SUM(IF(month(PROPERTIES.created_at) = 2, PROPERTIES.PROP_EXCLUSIVE = 'Exclusiva',0)) AS FEB
,SUM(IF(month(PROPERTIES.created_at) = 3, PROPERTIES.PROP_EXCLUSIVE = 'Exclusiva',0)) as MAR
,SUM(IF(month(PROPERTIES.created_at) = 4, PROPERTIES.PROP_EXCLUSIVE = 'Exclusiva',0)) AS ABR
,SUM(IF(month(PROPERTIES.created_at) = 5, PROPERTIES.PROP_EXCLUSIVE = 'Exclusiva',0)) AS MAY
,SUM(IF(month(PROPERTIES.created_at) = 6, PROPERTIES.PROP_EXCLUSIVE = 'Exclusiva',0)) as JUN
,SUM(IF(month(PROPERTIES.created_at) = 7, PROPERTIES.PROP_EXCLUSIVE = 'Exclusiva',0)) as JUL
,SUM(IF(month(PROPERTIES.created_at) = 8, PROPERTIES.PROP_EXCLUSIVE = 'Exclusiva',0)) AS AGO
,SUM(IF(month(PROPERTIES.created_at) = 9, PROPERTIES.PROP_EXCLUSIVE = 'Exclusiva',0)) as SEP
,SUM(IF(month(PROPERTIES.created_at) = 10, PROPERTIES.PROP_EXCLUSIVE = 'Exclusiva',0)) as OCT
,SUM(IF(month(PROPERTIES.created_at) = 11, PROPERTIES.PROP_EXCLUSIVE = 'Exclusiva',0)) as NOV
,SUM(IF(month(PROPERTIES.created_at) = 12, PROPERTIES.PROP_EXCLUSIVE = 'Exclusiva',0)) as DIC
FROM PROPERTIES
LEFT JOIN USERS ON PROPERTIES.PROP_CAPPER_EMAIL = USERS.EMAIL_LOCAL_CRM
WHERE   USERS.ID = 755
GROUP BY PROPERTIES.PROP_TYPE, USERS.ID
UNION
SELECT USERS.ID AS ID, 'Total'
,SUM(IF(MONTH(PROPERTIES.created_at) = 1, PROPERTIES.PROP_EXCLUSIVE = 'Exclusiva',0)) as ENE
,SUM(IF(month(PROPERTIES.created_at) = 2, PROPERTIES.PROP_EXCLUSIVE = 'Exclusiva',0)) AS FEB
,SUM(IF(month(PROPERTIES.created_at) = 3, PROPERTIES.PROP_EXCLUSIVE = 'Exclusiva',0)) as MAR
,SUM(IF(month(PROPERTIES.created_at) = 4, PROPERTIES.PROP_EXCLUSIVE = 'Exclusiva',0)) AS ABR
,SUM(IF(month(PROPERTIES.created_at) = 5, PROPERTIES.PROP_EXCLUSIVE = 'Exclusiva',0)) AS MAY
,SUM(IF(month(PROPERTIES.created_at) = 6, PROPERTIES.PROP_EXCLUSIVE = 'Exclusiva',0)) as JUN
,SUM(IF(month(PROPERTIES.created_at) = 7, PROPERTIES.PROP_EXCLUSIVE = 'Exclusiva',0)) as JUL
,SUM(IF(month(PROPERTIES.created_at) = 8, PROPERTIES.PROP_EXCLUSIVE = 'Exclusiva',0)) AS AGO
,SUM(IF(month(PROPERTIES.created_at) = 9, PROPERTIES.PROP_EXCLUSIVE = 'Exclusiva',0)) as SEP
,SUM(IF(month(PROPERTIES.created_at) = 10, PROPERTIES.PROP_EXCLUSIVE = 'Exclusiva',0)) as OCT
,SUM(IF(month(PROPERTIES.created_at) = 11, PROPERTIES.PROP_EXCLUSIVE = 'Exclusiva',0)) as NOV
,SUM(IF(month(PROPERTIES.created_at) = 12, PROPERTIES.PROP_EXCLUSIVE = 'Exclusiva',0)) as DIC
FROM PROPERTIES
LEFT JOIN USERS ON PROPERTIES.PROP_CAPPER_EMAIL = USERS.EMAIL_LOCAL_CRM
WHERE   USERS.ID = 755
GROUP BY USERS.ID

This is the code:

public function exclusive_details (Request $request) {
        $exclusive_details = DB::table('properties')
                            ->leftjoin('users', 'properties.prop_capper_email', '=', 'users.email_local_crm')
                            ->select(DB::raw("users.id
                            ,properties.prop_type
                            ,SUM(IF(MONTH(properties.created_at) = 1, properties.PROP_EXCLUSIVE = 'Exclusiva',0)) as ENE
                            ,SUM(IF(month(properties.created_at) = 2, properties.PROP_EXCLUSIVE = 'Exclusiva',0)) AS FEB
                            ,SUM(IF(month(properties.created_at) = 3, properties.PROP_EXCLUSIVE = 'Exclusiva',0)) as MAR
                            ,SUM(IF(month(properties.created_at) = 4, properties.PROP_EXCLUSIVE = 'Exclusiva',0)) AS ABR
                            ,SUM(IF(month(properties.created_at) = 5, properties.PROP_EXCLUSIVE = 'Exclusiva',0)) AS MAY
                            ,SUM(IF(month(properties.created_at) = 6, properties.PROP_EXCLUSIVE = 'Exclusiva',0)) as JUN
                            ,SUM(IF(month(properties.created_at) = 7, properties.PROP_EXCLUSIVE = 'Exclusiva',0)) as JUL
                            ,SUM(IF(month(properties.created_at) = 8, properties.PROP_EXCLUSIVE = 'Exclusiva',0)) AS AGO
                            ,SUM(IF(month(properties.created_at) = 9, properties.PROP_EXCLUSIVE = 'Exclusiva',0)) as SEP
                            ,SUM(IF(month(properties.created_at) = 10, properties.PROP_EXCLUSIVE = 'Exclusiva',0)) as OCT
                            ,SUM(IF(month(properties.created_at) = 11, properties.PROP_EXCLUSIVE = 'Exclusiva',0)) as NOV
                            ,SUM(IF(month(properties.created_at) = 12, properties.PROP_EXCLUSIVE = 'Exclusiva',0)) as DIC
                            "))
                            ->where('users.id', $request['query']['id'])
                            ->groupBy('properties.prop_type', 'users.id')
                            ->orderBy('properties.prop_type', 'asc');

        $exclusive_details_total = DB::table('properties')
                            ->leftjoin('users', 'properties.prop_capper_email', '=', 'users.email_local_crm')
                            ->select(DB::raw("users.id
                            ,'TOTAL'
                            ,SUM(IF(MONTH(properties.created_at) = 1, properties.PROP_EXCLUSIVE = 'Exclusiva',0)) as ENE
                            ,SUM(IF(month(properties.created_at) = 2, properties.PROP_EXCLUSIVE = 'Exclusiva',0)) AS FEB
                            ,SUM(IF(month(properties.created_at) = 3, properties.PROP_EXCLUSIVE = 'Exclusiva',0)) as MAR
                            ,SUM(IF(month(properties.created_at) = 4, properties.PROP_EXCLUSIVE = 'Exclusiva',0)) AS ABR
                            ,SUM(IF(month(properties.created_at) = 5, properties.PROP_EXCLUSIVE = 'Exclusiva',0)) AS MAY
                            ,SUM(IF(month(properties.created_at) = 6, properties.PROP_EXCLUSIVE = 'Exclusiva',0)) as JUN
                            ,SUM(IF(month(properties.created_at) = 7, properties.PROP_EXCLUSIVE = 'Exclusiva',0)) as JUL
                            ,SUM(IF(month(properties.created_at) = 8, properties.PROP_EXCLUSIVE = 'Exclusiva',0)) AS AGO
                            ,SUM(IF(month(properties.created_at) = 9, properties.PROP_EXCLUSIVE = 'Exclusiva',0)) as SEP
                            ,SUM(IF(month(properties.created_at) = 10, properties.PROP_EXCLUSIVE = 'Exclusiva',0)) as OCT
                            ,SUM(IF(month(properties.created_at) = 11, properties.PROP_EXCLUSIVE = 'Exclusiva',0)) as NOV
                            ,SUM(IF(month(properties.created_at) = 12, properties.PROP_EXCLUSIVE = 'Exclusiva',0)) as DIC
                            "))
                            ->where('users.id', $request['query']['id'])
                            ->union($exclusive_details)
                            ->groupBy('users.id')
                            ->get();
        dump($exclusive_details);
        return response()->json($exclusive_details);
    }

How can I fix the union issue?

Regards



via Chebli Mohamed

1 Salut, j'essaye de télécharger une image avec Laravel 5

I can't upload a file in laravel, it gives me the Method Illuminate \ Validation \ Validator :: validateAvatar does not exist error. so say that everything is well done

I created a validator function which return the validates



via Chebli Mohamed