dimanche 8 juillet 2018

Laravel unique department for each company

I have a table named departments where 2 columns 1. name 2. company, I want to apply validation on name for single company.

  public function store(Request $request)
 {
    $company = Auth::user()->company_id;
    $this->validate($request, [
        'company'=>'unique:departments,company',
    ]);

    $department = Department::create([
        'name' => $request->name,
        'company' => $request->company,
    ]);

expected result is

department company
======================
Accounts    1
Purchase    1
Accounts    2
Sales       2
Accounts    2  //wrong i want validation here
Purchase    1  //wrong i want validation here



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire