jeudi 29 novembre 2018

laravel mysql database same page multiple form submission table not updating

i am trying to update database table by using checkboxes ,the code is not giving any error,but the database table is not updating. My blade code where the form is:

<body>
        <h2>Reported Posts </h2>
        <a href="">Back</a> 

        <table>
        @foreach($post_reports as $post_report)
            <tr>
                <td>Report NO:</td>
                <td></td>
                <td></td>
    <form method="post">
        @csrf
                <td><input type="checkbox" name="statusyes[]" value= >report to admin  <input type="checkbox" name="statusno[]" value= >wrong report </td>
            </tr>
        @endforeach
        <td><input type="submit" name="submit" value="Submit" /></td>
    </form>
        </table>

my controller code is :

I am using the status_update_reported_post function

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Post_report;
use Illuminate\Support\Facades\DB;


class moderatorController extends Controller
{
    public function index(Request $request){

    return view('moderator.index');
   }

   public function reported_post(Request $request){

    $post_reports=DB::table('Post_reports')
                ->where('status','moderator')->get();

    return view('moderator.reported_post')-> with('post_reports',$post_reports);
   }

   public function status_update_reported_post(Request $request){
   $statusadmin[]=$request['statusyes'];
   $statuswrong[]=$request['statusno'];
   $r='admin';
   $wr='wrong';

   foreach($statusadmin as $report_id){
      DB::table('post_reports')
               ->where('report_id','$report_id')
               ->update(['status' => 'admin']);

   }

   foreach($statuswrong as $report_id){

        DB::table('post_reports')
               ->where('report_id','$report_id')
               ->update(['status' => 'wrong']);

   }
}


}

the code is working fine but there is no update in the table i dont know where the problem is, It all seems fine to me .



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

Aucun commentaire:

Enregistrer un commentaire