jeudi 4 octobre 2018

implement carbon to compare date (API)

public function searchresult (Request $request)
{
    $keyword = $request->name;


    $search = Mosque::where('name', 'LIKE',"%{$keyword}%" )->whereHas('events')->orWhereHas('activities')->get();

    return response()->json(['result' => $search]);    
}

//model mosque

namespace App;

use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes;

class Mosque extends Model { use SoftDeletes;

/**
 * The attributes that are mass assignable.
 *
 * @var array
 */
protected $fillable = [
    'state_id', 'area_id', 'name', 'latitude', 'longitude', 'address', 'image', 'type', 'referral_code', 'phone_number_1', 'phone_number_2', 'deleted_at'
];

public function events()
{
    return $this->hasMany('App\Event');
}
public function activities()
{
    return $this->hasMany('App\Activity');
}

}

this is my controller for search. the relation is the mosque has many events and activity. in the activities and events, i have column start date and end date. how I implement carbon to compare today date with the start date and compare today date with end date which will give the result only the mosque that has an event and activity between start date and end date. Thankyou



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire