PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, January 13, 2022

[FIXED] Update status problems

 January 13, 2022     forms, html, laravel, laravel-blade, php     No comments   

Issue

I'm trying to update status. if status is 0 then on click it must update it to 1. but if status is 1 on click it must update it to 0.

my controller

public function status(Course $course)
{
    if ($course->status == 0) {
        $course->update(['status' => '1']);
        return redirect('/profile')->with('statusOn', 'status on!');
    } else {
       $course->update(['status' => '0']);
       return redirect('/profile')->with('statusOff', 'status off!');
    }
}

route

Route::post('/course/status/{course}', [CourseManagementController::class, 'status']);

blade

  <form method="POST" action="/course/status/{{$c->id}}">
                            @csrf
                            @if($c->status == 0)
                            <button type="submit" class="btn btn-success">active</button>
                            @else
                            <button type="submit" class="btn btn-danger">deactive</button>
                            @endif
                        </form>

Solution

Hi there please debug !

public function status(Course $course)
{
    dump($course); // the data is okay or not

    if ($course->status == 0) {
        $status = $course->update(['status' => '1']);

        dd($status); // check the update status

        // return redirect('/profile')->with('statusOn', 'status on!');
    } else {
        $status = $course->update(['status' => '0']);

        dd($status); // check the update status

        // return redirect('/profile')->with('statusOff', 'status off!');
    }
}

If everything looks okay, please check fillable variable of your Course class, status might missing in fillable array



Answered By - abSiddique
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing