Skip to content
13 changes: 11 additions & 2 deletions app/Http/Controllers/Resources/BidsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,17 @@ public function index(Request $request, Task $task)
return DB::select('select * from bids b, users u where b.task_id = ? and b.user_id = u.id', [$task->id]);
}
}



public function maxprice(Task $task)
{
return DB::maxprice('SELECT MAX(price) FROM bids b, WHERE b.task_title = $task.task_title');
}

public function countbids(Task $task)
{
return DB::countbids('SELECT COUNT(bid) FROM tasks t, WHERE t.task_title = $task.task_title');
}

/**
* Update the selected field of the bid, whether is it true or false.
*
Expand Down
12 changes: 11 additions & 1 deletion app/Http/Controllers/Resources/TasksController.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,17 @@ public function edit(Task $task)
$generic_tasks = (object)DB::select("select * from generic_tasks");
return view('tasks.edit', compact('task', 'generic_tasks'));
}


public function search($query)
{
$tasks = (object)DB::select("SELECT * FROM tasks WHERE (title LIKE '%query%' OR start_date LIKE '%query%' OR end_date LIKE '%query%' OR created_at LIKE '%query%' OR category LIKE '%query%')";

//SELECT * FROM projectitem WHERE (description LIKE '%$keywords%' OR item LIKE '%$keywords%')";
//$tasks = Task::where('title','LIKE', "%$query%")->get();
//->orWhere('created_at','=', "$query")->orWhere('category','LIKE',"%$query%")->orWhere('start_date','=',"$query")->orWhere('end_date','=',"%$query%")->get();

return view('tasks.search')->withDetails($tasks)->withQuery($query);
}
/*
|--------------------------------------------------------------------------
| Resource Methods
Expand Down
7 changes: 7 additions & 0 deletions resources/views/home.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,16 @@
@if (sizeOf($tasks)>0)
<table class="table table-hover">
<tr>
<form action="tasks/search" method="GET">
<td> Search tasks: <input type="text" name ="q"> </td>
<td> <button type ="submit">Search </button> </td>
</form>
</tr>
<th>Title</th>
<th>Category</th>
<th>Start</th>
<th>End</th>
<th>Max Bid Price<th>
<th>Status</th>
<th><!-- edit button placeholder--></th>
</tr>
Expand All @@ -36,6 +42,7 @@
<td>{{$task->category}}</td>
<td>{{$task->start_date}}</td>
<td>{{$task->end_date}}</td>
<td>{{$task->max_bid_price}}</td>
<td>
@php
switch($task->status) {
Expand Down
39 changes: 39 additions & 0 deletions resources/views/tasks/search.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
@extends('layouts.app')


@section('content')

<div class="container">
@if(count($details) > 0)
<p> The Search results for your query <b> {{ $query }} </b> are :</p>
<h2>Task details</h2>
<table class="table table-striped">
<thead>
<tr>
<th>Title</th>
<th>Created_at</th>
<th>Category</th>
<th>Start_Date</th>
<th>End_Date</th>
</tr>
</thead>
<tbody>
@foreach($details as $task)
<tr onclick="window.document.location='tasks/{{$task->task_id}}';">
<td>{{$task->title}}</td>
<td>{{$task->create_at}}</td>
<td>{{$task->category}}</td>
<td>{{$task->start_date}}</td>
<td>{{$task->end_date}}</td>
</tr>
@endforeach
</tbody>
</table>
@else
No results found
@endif
</div>



@endsection
6 changes: 5 additions & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@
Route::get('/tasks/{task}/edit', 'Resources\TasksController@edit');
// this should be a post or a patch but Laravel gives a MethodNotAllowed error if it is anything but get
Route::get('/tasks/{task}/status/{status}', 'Resources\TasksController@updateStatus')->name('tasks.updateStatus');

Route::any('/tasks/search/{query}','Resources\TasksController@search');

Route::post('tasks/{task}/bids/{bid}/{selected}', 'Resources\BidsController@update')->name('bid.update');
Route::post('/tasks/{task}/bids', 'Resources\BidsController@store');
Route::patch('/tasks/{task}/bids/{bid}', 'Resources\BidsController@update');
Route::delete('/bids/{bid}', 'Resources\BidsController@destroy')->name('bid.destroy');
Route::any('/tasks/maxprice', 'Resources\BidsController@findmax');
Route::any('/tasks/countbids', 'Resources\BidsController@countbids');


Route::delete('/users/{user}', 'Resources\UsersController@destroy')->name('user.destroy');
Route::post('/users', 'Resources\UsersController@store');
Expand Down