app/Http/Controllers/User/SantriController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(Request $request)
    {
        request()->validate([
            'nama'      => 'required',
            'code'      => 'required|min:3|max:10|unique:santris,code|alpha_num',
            'alamat'    => 'required'
        ]);
        $code = userId() . '-' . request('code');
        $santri = Santri::whereCode($code)->whereUser_id(userId())->first();
        if ($santri) {
            session()->flash('warning', 'Code / ID ' . $santri->code . ' sudah ada, atas nama ' . $santri->nama);
            return Redirect::back();
        }
        Santri::create([
            'nama'      => request('nama'),
            'code'      => $code,
            'password'  => bcrypt('password'),
            'alamat'    => request('alamat'),
            'user_id'   => userId()
        ]);
        TimeLine('Data santri baru berhasil ditambahkan a.n ' . request('nama'));
        session()->flash('success', 'Data santri baru berhasil ditambahkan a.n ' . request('nama'));
        return Redirect::route('santri.index');
    }
public function store ( Request $ request ) { request ( ) -> validate ( [ 'nama' => 'required' , 'code' => 'required|min:3|max:10|unique:santris,code|alpha_num' , 'alamat' => 'required' ] ) ; $ code = userId ( ) . '-' . request ( 'code' ) ; $ santri = Santri :: whereCode ( $ code ) -> whereUser_id ( userId ( ) ) -> first ( ) ; if ( $ santri ) { session ( ) -> flash ( 'warning' , 'Code / ID ' . $ santri -> code . ' sudah ada, atas nama ' . $ santri -> nama ) ; return Redirect :: back ( ) ; } Santri :: create ( [ 'nama' => request ( 'nama' ) , 'code' => $ code , 'password' => bcrypt ( 'password' ) , 'alamat' => request ( 'alamat' ) , 'user_id' => userId ( ) ] ) ; TimeLine ( 'Data santri baru berhasil ditambahkan a.n ' . request ( 'nama' ) ) ; session ( ) -> flash ( 'success' , 'Data santri baru berhasil ditambahkan a.n ' . request ( 'nama' ) ) ; return Redirect :: route ( 'santri.index' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .