Where does the error occur? Which file, what line (and where in the code you posted is that line)?
Aug 3, 2022
9
Level 1
str_contains(): Argument #1 ($haystack) must be of type string, array given
I have a competitions table and it has the following fields.
public function up()
{
Schema::create('competitions', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
$table->foreignId('category_id')->constrained()->cascadeOnDelete();
$table->foreignId('team_a_id')->constrained('teams')->cascadeOnDelete();
$table->foreignId('team_b_id')->constrained('teams')->cascadeOnDelete();
$table->string('date');
$table->string('time');
$table->string('league');
$table->string('end_at');
$table->string('live')->nullable();
$table->timestamps();
});
}
And I want to search team_a_id and team_b_id in the teams' table.
Competition.php
public function team()
{
return $this->belongsTo(Team::class, ['team_a_id', 'team_a_id']);
}
CompetitionController.php
public function index()
{
$keyword = request('search') ?? null;
$competitions = Competition::query()
->whereHas('team', function ($query) use ($keyword) {
$query->where('title' , 'LIKE' , "%{$keyword}%");
})->paginate(25);
return view('Admin.competitions.index', compact('competitions'));
}
error
str_contains(): Argument #1 ($haystack) must be of type string, array given
Level 122
@esfer you can't have one relationship that covers both team columns
you will need to create a team_a method and a team_b method and add them both to your query
1 like
Please or to participate in this conversation.

