nikankad's avatar

my variable is not being passed to my view

im using two tables, so im using two models

this is my controller


namespace App\Http\Controllers\PastPaperControllesr;
use App\PastPapers;
use App\DropDown;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class IGCSEController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        $items = $request->items ?? 1;      // get the pagination number or a default

        // $club = Club::findOrFail(session('club'));

        
        // $pastpapers = PastPapers::all();
        $paper = PastPapers::orderBy('Code', 'desc');
        $pastpapers = $paper->paginate($items);
        $past1 = $paper->paginate($items); 
    
        $filters = DropDown::all();


        return view('pages/pastpapers/igcse')
        ->withPaper($paper)
        ->withPastpapers($pastpapers)
        ->withItems($items)
        ->withfilter($filters);
    }

    
    

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}

this is my model


namespace App;

use Illuminate\Database\Eloquent\Model;

class DropDown extends Model
{
    //table name
    protected $table = 'igcse_subjects';
    //primary key
    public $primaryKey = 'id';
    //timestaps
    public $timestaps = true;
}
0 likes
6 replies
himanshurajvanshi's avatar
Level 3

I am not sure you can send value like that

    return view('pages/pastpapers/igcse')
    ->withPaper($paper)
    ->withPastpapers($pastpapers)
    ->withItems($items)
    ->withfilter($filters);

but you can send value

 return view('pages/pastpapers/igcse',compact('paper','pastpapers','items','filters'));
or

return View::make('pages/pastpapers/igcse'')->with(['paper', $paper,]);

Sinnbeck's avatar

Your namespace also has a typo

namespace App\Http\Controllers\PastPaperControllesr;

Should be 
namespace App\Http\Controllers\PastPaperControllers;
Sinnbeck's avatar

Ok. I would recommend getting that fixed. Rename the folder, namespace and references in web.php, then run

composer dump-autoload
Tray2's avatar

Or you can do this

 return view('pages/pastpapers/igcse')->with([
    'paper' =>$paper,        
        'pastpapers'=> $pastpapers,
        'items' => $items,
        'filter' => $filter
]);

Since you are mixing plural and sigular in your code make sure you have the same variable names in your view.

Please or to participate in this conversation.