Advertisement
Guest User

Untitled

a guest
Dec 15th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.69 KB | None | 0 0
  1. class Student extends Model
  2. {
  3.     protected $fillable = [
  4.  
  5.         'first_name', 'preferred_name', 'sir_name', 'gender', 'date_of_birth', 'address', 'nationality','date_of_expiry',
  6.         'email', 'mobile', 'attendance_type', 'year_of_entry', 'level_of_entrance', 'your_first_language', 'passport_number',
  7.         'passport_date_of_expiry','religion', 'race', 'present_school_name', 'present_school_address', 'present_school_email',
  8.         'disciplinary_record',
  9.  
  10.         'guardian_id',
  11.  
  12.     ];
  13.  
  14.     public function guardian()
  15.     {
  16.         return $this->belongsTo(Guardian::class);
  17.     }
  18. }
  19.  
  20. class Guardian extends Model
  21. {
  22.     public $timestamps = false;
  23.  
  24.     protected $fillable = [
  25.         //parent/guardian details
  26.         'father_sir_name','father_first_name', 'father_address','father_telephone_home','father_telephone_business',
  27.         'father_email','father_occupation','father_employer','father_employer_address','father_mobile',
  28.  
  29.         'mother_sir_name','mother_first_name','mother_address', 'mother_telephone_home','mother_telephone_business',
  30.         'mother_email','mother_occupation','mother_employer','mother_employer_address','mother_mobile',
  31.  
  32.         'guardian_sir_name','guardian_first_name','guardian_address','guardian_telephone_home','guardian_telephone_business',
  33.         'guardian_email','guardian_occupation','guardian_employer','guardian_employer_address','guardian_mobile',
  34.     ];
  35.     public function students()
  36.     {
  37.         return $this->hasMany(Student::class, 'guardian_id');
  38.  
  39.     }
  40. }
  41. class CreateStudentsTable extends Migration
  42. {
  43. public function up()
  44.     {
  45.         Schema::create('students', function (Blueprint $table) {
  46.             $table->increments('id');
  47.             $table->string('first_name');
  48.             $table->string('preferred_name');
  49.             $table->string('sir_name');
  50.             $table->string('gender');
  51.             $table->date('date_of_birth');
  52.             $table->string('address');
  53.             $table->string('email');
  54.             $table->string('mobile');
  55.             $table->string('attendance_type');
  56.             $table->date('year_of_entry');
  57.             $table->string('level_of_entrance');
  58.             $table->string('nationality');
  59.             $table->string('your_first_language');
  60.             $table->string('passport_number');
  61.             $table->date('passport_date_of_expiry');
  62.             $table->string('religion');
  63.             $table->string('race');
  64.             $table->string('present_school_name');
  65.             $table->string('present_school_address');
  66.             $table->string('present_school_email');
  67.             $table->string('disciplinary_record');
  68.  
  69.             $table->integer('guardian_id')->unsigned();
  70.             $table->foreign('guardian_id')->references('id')->on('guardians')
  71.                   ->onUpdate('cascade')->onDelete('cascade');
  72.             $table->timestamps();
  73.         });
  74.     }
  75. }
  76.  
  77. class CreateGuardiansTable extends Migration
  78. {
  79.     /**
  80.      * Run the migrations.
  81.      * parent/guardian details
  82.     'father_sir_name','father_first_name', 'father_address','father_telephone_home','father_telephone_business','father_mobile',
  83.     'father_email','father_occupation','father_employer','father_employer_address',
  84.  
  85.     'mother_sir_name','mother_first_name','mother_address', 'mother_telephone','mother_telephone_business','mother_mobile',
  86.     'mother_email','mother_occupation','mother_employer','mother_employer_address',
  87.  
  88.     'guardian_sir_name','guardian_first_name','guardian_address','guardian_telephone','guardian_telephone_business','guardian_mobile',
  89.     'guardian_email','guardian_occupation','guardian_employer','guardian_employer_address',
  90.      *
  91.      *
  92.      * @return void
  93.      */
  94.     public function up()
  95.     {
  96.         Schema::create('guardians', function (Blueprint $table) {
  97.             $table->increments('id');
  98.             $table->string('father_sir_name');
  99.             $table->string('father_first_name');
  100.             $table->string('father_address');
  101.             $table->string('father_telephone_home');
  102.             $table->string('father_telephone_business');
  103.             $table->string('father_mobile');
  104.             $table->string('father_email');
  105.             $table->string('father_occupation');
  106.             $table->string('father_employer');
  107.             $table->string('father_employer_address');
  108.  
  109.             $table->string('mother_sir_name');
  110.             $table->string('mother_first_name');
  111.             $table->string('mother_address');
  112.             $table->string('mother_telephone_home');
  113.             $table->string('mother_telephone_business');
  114.             $table->string('mother_mobile');
  115.             $table->string('mother_email');
  116.             $table->string('mother_occupation');
  117.             $table->string('mother_employer');
  118.             $table->string('mother_employer_address');
  119.  
  120.             $table->string('guardian_sir_name');
  121.             $table->string('guardian_first_name');
  122.             $table->string('guardian_address');
  123.             $table->string('guardian_telephone_home');
  124.             $table->string('guardian_telephone_business');
  125.             $table->string('guardian_mobile');
  126.             $table->string('guardian_email');
  127.             $table->string('guardian_occupation');
  128.             $table->string('guardian_employer');
  129.             $table->string('guardian_employer_address');
  130.  
  131.  
  132.             $table->timestamps();
  133.         });
  134.     }
  135.  
  136. }
  137.  
  138. class StudentController extends Controller
  139. {
  140.    public function store(Request $request)
  141.     {
  142.         $student = Student::create($request->all());
  143.         $student->guardian()->create($request->all());
  144.         return redirect()->back();
  145.     }
  146. }
  147.  
  148.  Route::resource('students', 'StudentController');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement