jhutto
7 months ago

Cleaner Controllers

Posted 7 months ago by jhutto

I recently watched the Laravel 5.7 From Scratch - Cleaner Controllers and Mass Assignment Concerns Video

And I started working on cleaning up my controllers. Then I ran into this one.

CHECKBOXES....

How do I get check boxes into this format......

Instructor::update(request(['FirstName', 'LastName']));

Here's my current update function (condensed of course)

$instructor = \App\Instructor::find($id);
        $instructor->FirstName = $request->FirstName;
        $instructor->LastName = $request->LastName;
        

        if (!$request->has('Viewable'))
        {
            // Checkbox is checked
            $instructor->Active = "0";
            
        }
        else
        {
             // Checkbox is not checked
             $instructor->Active = "1";
        }

                
        $instructor->save();

Thanks

Please sign in or create an account to participate in this conversation.