app/Http/Controllers/MahasiswaController.php
/**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
Show the form for creating a new resource.
@return \Illuminate\Http\Response
Show the form for creating a new resource . @return \ Illuminate \ Http \ Response
public function create(CreateMahasiswaRequest $request)
    {
        $user = new \App\Models\User;
        $user->role = 'mahasiswa';
        $user->name = $request->nama;
        $user->email = $request->email;
        $user->password = bcrypt('passwordmahasiswa');
        $user->remember_token = Str::random(60);
        $user->save();
        $request->request->add(['user_id' => $user->id]);
        $mahasiswa = Mahasiswa::create($request->all());
        if($request->hasFile('avatar')) {
            $request->file('avatar')->move('images/', $request->file('avatar')->getClientOriginalName());
            $mahasiswa->avatar = $request->file('avatar')->getClientOriginalName();
            $mahasiswa->save();
        }
        return redirect('/mahasiswa')->with('sukses','Data Berhasil di input');
    }
public function create ( CreateMahasiswaRequest $ request ) { $ user = new \ App \ Models \ User ; $ user -> role = 'mahasiswa' ; $ user -> name = $ request -> nama ; $ user -> email = $ request -> email ; $ user -> password = bcrypt ( 'passwordmahasiswa' ) ; $ user -> remember_token = Str :: random ( 60 ) ; $ user -> save ( ) ; $ request -> request -> add ( [ 'user_id' => $ user -> id ] ) ; $ mahasiswa = Mahasiswa :: create ( $ request -> all ( ) ) ; if ( $ request -> hasFile ( 'avatar' ) ) { $ request -> file ( 'avatar' ) -> move ( 'images/' , $ request -> file ( 'avatar' ) -> getClientOriginalName ( ) ) ; $ mahasiswa -> avatar = $ request -> file ( 'avatar' ) -> getClientOriginalName ( ) ; $ mahasiswa -> save ( ) ; } return redirect ( '/mahasiswa' ) -> with ( 'sukses' , 'Data Berhasil di input' ) ; }
Show the form for creating a new resource.
Show the form for creating a new resource .
//inisialisasi store data user //add user_id //store data ke tabel mahasiswa //pengecekan gambar dan mengalihkan gambar ke folder images