Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Student extends Model
- {
- protected $fillable = [
- 'first_name', 'preferred_name', 'sir_name', 'gender', 'date_of_birth', 'address', 'nationality','date_of_expiry',
- 'email', 'mobile', 'attendance_type', 'year_of_entry', 'level_of_entrance', 'your_first_language', 'passport_number',
- 'passport_date_of_expiry','religion', 'race', 'present_school_name', 'present_school_address', 'present_school_email',
- 'disciplinary_record',
- 'guardian_id',
- ];
- public function guardian()
- {
- return $this->belongsTo(Guardian::class);
- }
- }
- class Guardian extends Model
- {
- public $timestamps = false;
- protected $fillable = [
- //parent/guardian details
- 'father_sir_name','father_first_name', 'father_address','father_telephone_home','father_telephone_business',
- 'father_email','father_occupation','father_employer','father_employer_address','father_mobile',
- 'mother_sir_name','mother_first_name','mother_address', 'mother_telephone_home','mother_telephone_business',
- 'mother_email','mother_occupation','mother_employer','mother_employer_address','mother_mobile',
- 'guardian_sir_name','guardian_first_name','guardian_address','guardian_telephone_home','guardian_telephone_business',
- 'guardian_email','guardian_occupation','guardian_employer','guardian_employer_address','guardian_mobile',
- ];
- public function students()
- {
- return $this->hasMany(Student::class, 'guardian_id');
- }
- }
- class CreateStudentsTable extends Migration
- {
- public function up()
- {
- Schema::create('students', function (Blueprint $table) {
- $table->increments('id');
- $table->string('first_name');
- $table->string('preferred_name');
- $table->string('sir_name');
- $table->string('gender');
- $table->date('date_of_birth');
- $table->string('address');
- $table->string('email');
- $table->string('mobile');
- $table->string('attendance_type');
- $table->date('year_of_entry');
- $table->string('level_of_entrance');
- $table->string('nationality');
- $table->string('your_first_language');
- $table->string('passport_number');
- $table->date('passport_date_of_expiry');
- $table->string('religion');
- $table->string('race');
- $table->string('present_school_name');
- $table->string('present_school_address');
- $table->string('present_school_email');
- $table->string('disciplinary_record');
- $table->integer('guardian_id')->unsigned();
- $table->foreign('guardian_id')->references('id')->on('guardians')
- ->onUpdate('cascade')->onDelete('cascade');
- $table->timestamps();
- });
- }
- }
- class CreateGuardiansTable extends Migration
- {
- /**
- * Run the migrations.
- * parent/guardian details
- 'father_sir_name','father_first_name', 'father_address','father_telephone_home','father_telephone_business','father_mobile',
- 'father_email','father_occupation','father_employer','father_employer_address',
- 'mother_sir_name','mother_first_name','mother_address', 'mother_telephone','mother_telephone_business','mother_mobile',
- 'mother_email','mother_occupation','mother_employer','mother_employer_address',
- 'guardian_sir_name','guardian_first_name','guardian_address','guardian_telephone','guardian_telephone_business','guardian_mobile',
- 'guardian_email','guardian_occupation','guardian_employer','guardian_employer_address',
- *
- *
- * @return void
- */
- public function up()
- {
- Schema::create('guardians', function (Blueprint $table) {
- $table->increments('id');
- $table->string('father_sir_name');
- $table->string('father_first_name');
- $table->string('father_address');
- $table->string('father_telephone_home');
- $table->string('father_telephone_business');
- $table->string('father_mobile');
- $table->string('father_email');
- $table->string('father_occupation');
- $table->string('father_employer');
- $table->string('father_employer_address');
- $table->string('mother_sir_name');
- $table->string('mother_first_name');
- $table->string('mother_address');
- $table->string('mother_telephone_home');
- $table->string('mother_telephone_business');
- $table->string('mother_mobile');
- $table->string('mother_email');
- $table->string('mother_occupation');
- $table->string('mother_employer');
- $table->string('mother_employer_address');
- $table->string('guardian_sir_name');
- $table->string('guardian_first_name');
- $table->string('guardian_address');
- $table->string('guardian_telephone_home');
- $table->string('guardian_telephone_business');
- $table->string('guardian_mobile');
- $table->string('guardian_email');
- $table->string('guardian_occupation');
- $table->string('guardian_employer');
- $table->string('guardian_employer_address');
- $table->timestamps();
- });
- }
- }
- class StudentController extends Controller
- {
- public function store(Request $request)
- {
- $student = Student::create($request->all());
- $student->guardian()->create($request->all());
- return redirect()->back();
- }
- }
- Route::resource('students', 'StudentController');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement