Created
September 9, 2017 14:27
-
-
Save 3h5a9/5c64ca9e58029bb550019621e1717e62 to your computer and use it in GitHub Desktop.
Error Showing -- Undefined variable: students
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace App\Http\Controllers; | |
| use App\Http\Requests; | |
| use Illuminate\Http\Request; | |
| use Session; | |
| class HomeController extends Controller | |
| { | |
| /** | |
| * Create a new controller instance. | |
| * | |
| * @return void | |
| */ | |
| public function __construct() | |
| { | |
| $this->middleware('auth'); | |
| } | |
| /** | |
| * Show the application dashboard. | |
| * | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function getHome() | |
| { | |
| return view('pages.home'); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* | |
| |-------------------------------------------------------------------------- | |
| | Application Routes | |
| |-------------------------------------------------------------------------- | |
| | | |
| | Here is where you can register all of the routes for an application. | |
| | It's a breeze. Simply tell Laravel the URIs it should respond to | |
| | and give it the controller to call when that URI is requested. | |
| | | |
| */ | |
| Route::get('/', function () { | |
| return view('pages.welcome'); | |
| }); | |
| Route::auth(); | |
| Route::get('/home', 'HomeController@getHome'); | |
| Route::resource('home/student', 'StudentController'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace App\Http\Controllers; | |
| use Illuminate\Http\Request; | |
| use App\Http\Requests; | |
| use App\Student; | |
| class StudentController extends Controller | |
| { | |
| public function __construct() | |
| { | |
| $this->middleware('auth'); | |
| } | |
| /** | |
| * Display a listing of the resource. | |
| * | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function index() | |
| { | |
| //Show All | |
| $students = Student::all(); | |
| return view('pages.students', compact('student') ); | |
| } | |
| /** | |
| * Show the form for creating a new resource. | |
| * | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function create() | |
| { | |
| return view('pages.create'); | |
| } | |
| /** | |
| * Store a newly created resource in storage. | |
| * | |
| * @param \Illuminate\Http\Request $request | |
| * @return \Illuminate\Http\Response | |
| */ | |
| public function store(Request $request) | |
| { | |
| //Validate | |
| $this->validate($request, array( | |
| 'fname' => 'required|max:255', | |
| 'mname' => 'required', | |
| 'lname' => 'required', | |
| 'dob' => 'required', | |
| 'gender' => 'required', | |
| 'bloodgroup' => 'required', | |
| 'bplace' => 'required', | |
| 'nationality' => 'required', | |
| 'religion' => 'required', | |
| 'presentadd' => 'required', | |
| 'permanentadd' => 'required', | |
| 'city' => 'required', | |
| 'ps' => 'required', | |
| 'zipcode' => 'required', | |
| 'phone' => 'required', | |
| 'mobile' => 'required', | |
| 'email' => 'required|unique:students,email', | |
| 'roll' => 'required|unique:students,roll', | |
| 'class' => 'required', | |
| 'section' => 'required' | |
| )); | |
| // Store | |
| $student = new Student; | |
| $student->fname = $request->fname; | |
| $student->mname = $request->mname; | |
| $student->lname = $request->lname; | |
| $student->dob = $request->dob; | |
| $student->gender = $request->gender; | |
| $student->bloodgroup = $request->bloodgroup; | |
| $student->bplace = $request->bplace; | |
| $student->nationality = $request->nationality; | |
| $student->religion = $request->religion; | |
| $student->presentadd = $request->presentadd; | |
| $student->permanentadd = $request->permanentadd; | |
| $student->city = $request->city; | |
| $student->ps = $request->ps; | |
| $student->zipcode = $request->zipcode; | |
| $student->phone = $request->phone; | |
| $student->mobile = $request->mobile; | |
| $student->email = $request->email; | |
| $student->roll = $request->roll; | |
| $student->class = $request->class; | |
| $student->section = $request->section; | |
| $student->save(); | |
| // Redirect | |
| return redirect()->route('home.student.index'); | |
| } | |
| /** | |
| * 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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @extends('layouts.app') | |
| @section('title', 'All Student List') | |
| @section('stylesheet') | |
| <style></style> | |
| @stop | |
| @section('content') | |
| <div class="container"> | |
| <div class="row"> | |
| <div class="col-md-12"> | |
| <table class="table table-responsive table-striped table-bordered table-condensed"> | |
| <thead> | |
| <tr> | |
| <th>ID</th> | |
| <th>Name</th> | |
| <th>Roll</th> | |
| </tr> | |
| </thead> | |
| <tbody> | |
| @foreach($students as $student) | |
| <tr> | |
| <td>{{$student->id}}</td> | |
| </tr> | |
| @endforeach | |
| </tbody> | |
| </table> | |
| </div> | |
| </div> | |
| </div> | |
| @endsection |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The problem is in student controller.
$students = Student::all(); return view('pages.students', compact('student') );Should be
compact('students');