app/Http/Controllers/DebtorController.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)
    {
 $this->validate($request, [
 'name' => 'required|regex:/^[A-Z][a-ząęćłóńżźś]{1,15}\s[A-Z][a-ząęćłóńżźś]{0,15}$/',
 'email' => 'email',
 'money' =>'regex:/^\d+(\.\d{1,2})?$/'
 ]);
 if(\Auth::user() == null){
     return view('welcome');
 }
 $debtor = new Debtor();
 $debtor->user_id=\Auth::user()->id;
 $debtor->name=$request->name;
 $debtor->email=$request->email;
 $debtor->money=$request->money;
 if($debtor->save()){
     return redirect('debtor');
 }
 return view('debtor');
    }
public function store ( Request $ request ) { $ this -> validate ( $ request , [ 'name' => 'required|regex:/^[A-Z][a-ząęćłóńżźś]{1,15}\s[A-Z][a-ząęćłóńżźś]{0,15}$/', 'email' => 'email' , 'money' => 'regex:/^\d+(\.\d{1,2})?$/' ] ) ; if ( \ Auth :: user ( ) == null ) { return view ( 'welcome' ) ; } $ debtor = new Debtor ( ) ; $ debtor -> user_id = \ Auth :: user ( ) -> id ; $ debtor -> name = $ request -> name ; $ debtor -> email = $ request -> email ; $ debtor -> money = $ request -> money ; if ( $ debtor -> save ( ) ) { return redirect ( 'debtor' ) ; } return view ( 'debtor' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
// Podstawowa walidacja formularza: