vendredi 21 octobre 2016

How to use unique in laravel queries

I don't want a user to ask the same question twice

If user 'John' has a question 'Whats the time?', he shouldn't be able to post it again, although a different user can post the same question!

This is my laravel rule code for validation the 'question' text field:

public function rules()
{
    return [
        'question'=>'required|unique:questions,question,2,people_id'
    ];
}

But this is allowing the user with id '2' to post the question, how do I fix it. Also, how can I replace '2' with Auth::id(), it shows error 'undefined class constant id' ?

Table structure

questions-> table name
question-> column name
people_id-> where Auth Id is stored, like '2'



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire