dimanche 9 octobre 2016

Laravel return a value if it is not unique

I am checking if the value is unique or not in the database using validation and here is the code:

 public function store(Request $request)
        {
            $select = 'select';

            //logged in user id
            $userid         = Auth::user() -> id;
            $usercountry    = Auth::user() -> country;

            $this -> validate($request, array(
                'number'        => 'required | unique:leads',
                'website'       => 'required | unique:leads',
                'lead_source'   => 'required | not_in:' . $select,
                'industry'      => 'required | not_in:' . $select,
                'action'        => 'required | not_in:' . $select
            ));
}

This works perfect but it show me a message telling me if the website input is duplicated or not.

What I am trying to do is to return a value from the table leads which contain the website column.

I found this code:

if ($validator->fails()) {
            $failedRules = $validator->failed();

        }

How I could modify it to return a value from the same duplicated row in the leads table?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire