Angular & Laravel 高级搜索

Angular & Laravel Advanced Searching

我正在使用 Angular12 作为前端,使用 Laravel 作为后端进行完全卡住的开发。我想使用多个值进行搜索,但我不知道。我可以使用单个值进行搜索,但我想使用多个值(AND 运算)。

LARAVEL

api.php:

Route::get('/project/search/{request}', [ProjectController::class, 'search']);

ProjectController.php:

public function search($request)
{
    if ($request==='business_divition') {
        return Project::where('business_divition', 'like', '%Business%')->get();
    }

    if ($request==='rank') {
        return Project::where('rank', 'like', '%rank%')->get();
    }
    
    //Single value search
    //return Project::where('rank', 'like', '%' .$request. '%')->get();
}

Angular

data.service.ts:

searchProjectData(data: any) {
    return this.httpClient.get('http://127.0.0.1:8000/api/project/search',data);
}

itemlist.component.ts:

search() {
    this.dataService.searchProjectData(this.projects).subscribe(res => {
      this.projects = res; //right now 'res' value display as *null*
    })
}

itemlist.component.html:

<p-dropdown [options]="rankArr" name="rank" [(ngModel)]="project.rank" optionLabel="rank" optionValue="rank"></p-dropdown>
<p-dropdown [options]="divitionArr" name="business_divition" [(ngModel)]="project.business_divition" optionLabel="divition" optionValue="divition"></p-dropdown>

<button (click)="search()" type="button"></button>

我认为itemlist.component.ts文件search()方法是错误的!

您的 url 看起来不像服务器端的那个。这个功能会起作用。我使用动态 url 来适应你的所有情况。

searchProjectData (data: string) { 
let url = "http://127.0.0.1:8000/api/project/search/" + data;
return this.httpClient.get(url);
 }