[Vuejs]-How to fetch data from another table? so that I can make a condition and make a relationship (Laravel + Vue)

0👍

You are calling data_start_raise() without actually telling it what entry to do it on

['date_input','>=', Cycle::date_start_raise()],
 ['date_input','<=', Cycle::date_end_raise()

You would have to find an entry for example

Cycle::find( id goes here )->date_start_raise()

https://laravel.com/docs/5.7/eloquent

0👍

  public function store(Request $request)
        {
         $cycle = Mortality::whereDate([
         [request('date_input'),'>=', Cycle::date_start_raise()],
         [request('date_input'),'<=', Cycle::date_end_raise()],
         ])->get()->first();

         if ($cycle!==NULL)
           { $cycle_id = $cycle->id;}
         else return;//you may send with an error message like invalid date
         //above lines are a little bit changed.

         $this->validate($request, array(
           'date_input' => 'required|date',
           'number_of_mortality' => 'required|numeric',
           'chicken_age' => 'required|numeric'
           ));

         return Mortality::create([
           'date_input' => request('date_input'),
           'number_of_mortality' => request('number_of_mortality'),
           'chicken_age' => request('chicken_age'),
           'cause_of_death' => request('cause_of_death'),
           'cycle_id' => $cycle_id,
           'user_id' => Auth::id()
           ]);
       }

When you used get method with where clause, you were getting a collection; not a single instance. That is why you couldn’t assign the id. By using first(), we are getting a single id.

Leave a comment