0

i know there's alot of solutions for this question but i tried everything possible but i couldn't fix it here's my view called Provider-Unplanned.blade.php the error is :

ErrorException Undefined variable: emps (View: C:\xampp\htdocs\laravel\PFE\resources\views\admin\Provider-Unplanned.blade.php)

<table class="table table-striped table-dark">
    <thead>
        <tr>
            <th scope="col"> ID </th>
            <th scope="col">NAME </th>
            <th scope="col"> CODE </th>
            <th scope="col">SITE </th>
            <th scope="col">DATE </th>
            <th scope="col"> MATRICULE</th>
            <th scope="col"> ARRIVAGE</th>
            <th scope="col"> ENTRER</th>
            <th scope="col"> SORTIE</th>
        </tr>
    </thead>
    <tbody>
    @foreach($emps as $emp)
        <tr>
            <td>{{$emp->id}}</td>
            <td>{{$emp->name}}</td>
            <td>{{$emp->code}}</td>
            <td>{{$emp->site}}</td>
            <td>{{$emp->date}}</td>
            <td>{{$emp->matricule}}</td>
            <td>{{$emp->arrivage}}</td>
            <td>{{$emp->entrer}}</td>
            <td>{{$emp->sortie}}</td>
        </tr>
    @endforeach
    </tbody>
</table>    

here's the controller code called ProviderController

<?php

namespace App\Http\Controllers\Admin;
use DB;
use Session;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\fournisseursjour;
use App\unplannedprovider;


class ProviderController extends Controller
{
public function ProviderUnplan(){
        return view('admin.Provider-Unplanned');
    }
 /* UNPLANNED PROVIDER */

    //DB Unplanned Provider
    public function unplanned()
    {
        $emps= unplannedprovider::all();
        return view('Provider-Unplanned')->with('emps',$emps);
    }
    //unplanned provider CRUD

    public function NewUnplanned(Request $request)
    {
       $this->validate($request,[
       'name'=>'required',
       'code'=>'required',
       'site'=>'required',
       'date'=>'required',
       'matricule'=>'nullable',
       'arrivage'=>'nullable',
       'entrer'=>'nullable',
       'sortie'=>'nullable',
     ]);
        $emps=new unplannedprovider;
        $emps->name=$request->input('name');
        $emps->code=$request->input('code');
        $emps->site=$request->input('site');
        $emps->date=$request->input('date');
        $emps->matricule=$request->input('matricule');
        $emps->arrivage=$request->input('arrivage');
        $emps->entrer=$request->input('entrer');
        $emps->sortie=$request->input('sortie');

        $emps->save();
        return redirect('Provider-Unplanned')->with('success','Data Saved');
    }
    

}

finally web.php

Route::get('/Provider-Unplanned','Admin\ProviderController@ProviderUnplan')->name('ProviderUnplan');

Route::post('/Provider-Unplanned','Admin\ProviderController@NewUnplanned');
miken32
  • 42,008
  • 16
  • 111
  • 154
  • 2
    Welcome to SO ... your method `ProviderUnplan` is not passing any data to the view, `admin.Provider-Unplanned` ... that view is expecting a `$emps` variable to iterate – lagbox Mar 25 '21 at 22:17
  • thank you for responding... can you tell me how to fix it exactly? i'm new to Laravel programming i'm still learning and i guess i didn't get your point :( – Smii Hajer ELF Mar 25 '21 at 22:26
  • 1
    you would need to pass what ever that `$emps` is supposed to be to that view similar to how you are in the `unplanned` method – lagbox Mar 25 '21 at 22:29
  • `return view('admin.Provider-Unplanned');` where is `with()` method? – miken32 Mar 26 '21 at 03:29
  • you mean like this? ` public function unplanned() { $emps= 'this is a test';//unplannedprovider::all(); return view('Provider-Unplanned')->with('emps', $emps); } ` it's stil not working – Smii Hajer ELF Mar 26 '21 at 10:10

0 Answers0