Browse Source

Composer update to lv 5.4.23

Added Api/ProductsController for ajax product search
Extract authentication routes into routes/web.php
pull/5/head
Nafies Luthfi 9 years ago
parent
commit
ae999aa03a
  1. 24
      app/Http/Controllers/Api/ProductsController.php
  2. 30
      composer.lock
  3. 15
      routes/api.php
  4. 5
      routes/web.php
  5. 33
      tests/Feature/Cart/SearchProductsTest.php
  6. 16
      tests/TestCase.php

24
app/Http/Controllers/Api/ProductsController.php

@ -0,0 +1,24 @@
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Product;
use Illuminate\Http\Request;
class ProductsController extends Controller
{
public function search(Request $request)
{
$query = $request->get('query');
$queriedProducts = [];
if ($query) {
$queriedProducts = Product::where(function ($q) use ($query) {
$q->where('name', 'like', '%'.$query.'%');
})->with('unit')->get();
}
return response()->json($queriedProducts, 200);
// return view('cart.partials.product-search-result-box', $queriedProducts);
}
}

30
composer.lock

@ -493,16 +493,16 @@
},
{
"name": "laravel/framework",
"version": "v5.4.21",
"version": "v5.4.23",
"source": {
"type": "git",
"url": "https://github.com/laravel/framework.git",
"reference": "2ed668f96d1a6ca42f50d5c87ee9ceecfc0a6eee"
"reference": "ad82327705658dbf5f0ce72805caa950dfbe150d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/laravel/framework/zipball/2ed668f96d1a6ca42f50d5c87ee9ceecfc0a6eee",
"reference": "2ed668f96d1a6ca42f50d5c87ee9ceecfc0a6eee",
"url": "https://api.github.com/repos/laravel/framework/zipball/ad82327705658dbf5f0ce72805caa950dfbe150d",
"reference": "ad82327705658dbf5f0ce72805caa950dfbe150d",
"shasum": ""
},
"require": {
@ -618,20 +618,20 @@
"framework",
"laravel"
],
"time": "2017-04-28T15:40:01+00:00"
"time": "2017-05-11T20:10:35+00:00"
},
{
"name": "laravelcollective/html",
"version": "v5.4.1",
"version": "v5.4.3",
"source": {
"type": "git",
"url": "https://github.com/LaravelCollective/html.git",
"reference": "7570f25d58a00fd6909c0563808590f9cdb14d47"
"reference": "023efce5fd8057cb3b5ce503f3391cc4effa7caa"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/LaravelCollective/html/zipball/7570f25d58a00fd6909c0563808590f9cdb14d47",
"reference": "7570f25d58a00fd6909c0563808590f9cdb14d47",
"url": "https://api.github.com/repos/LaravelCollective/html/zipball/023efce5fd8057cb3b5ce503f3391cc4effa7caa",
"reference": "023efce5fd8057cb3b5ce503f3391cc4effa7caa",
"shasum": ""
},
"require": {
@ -672,7 +672,7 @@
],
"description": "HTML and Form Builders for the Laravel Framework",
"homepage": "http://laravelcollective.com",
"time": "2017-01-26T19:27:05+00:00"
"time": "2017-05-15T09:38:20+00:00"
},
{
"name": "league/flysystem",
@ -1327,16 +1327,16 @@
},
{
"name": "swiftmailer/swiftmailer",
"version": "v5.4.7",
"version": "v5.4.8",
"source": {
"type": "git",
"url": "https://github.com/swiftmailer/swiftmailer.git",
"reference": "56db4ed32a6d5c9824c3ecc1d2e538f663f47eb4"
"reference": "9a06dc570a0367850280eefd3f1dc2da45aef517"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/swiftmailer/swiftmailer/zipball/56db4ed32a6d5c9824c3ecc1d2e538f663f47eb4",
"reference": "56db4ed32a6d5c9824c3ecc1d2e538f663f47eb4",
"url": "https://api.github.com/repos/swiftmailer/swiftmailer/zipball/9a06dc570a0367850280eefd3f1dc2da45aef517",
"reference": "9a06dc570a0367850280eefd3f1dc2da45aef517",
"shasum": ""
},
"require": {
@ -1377,7 +1377,7 @@
"mail",
"mailer"
],
"time": "2017-04-20T17:32:18+00:00"
"time": "2017-05-01T15:54:03+00:00"
},
{
"name": "symfony/console",

15
routes/api.php

@ -2,17 +2,6 @@
use Illuminate\Http\Request;
/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/
Route::middleware('auth:api')->get('/user', function (Request $request) {
return $request->user();
Route::group(['prefix' => 'v1','namespace' => 'Api', 'as' => 'api.', 'middleware' => []], function() {
Route::post('products/search', ['as' => 'products.search', 'uses' => 'ProductsController@search']);
});

5
routes/web.php

@ -15,7 +15,10 @@ Route::get('/', function () {
return redirect()->route('login');
});
Auth::routes();
// Authentication Routes...
Route::get('login', 'Auth\LoginController@showLoginForm')->name('login');
Route::post('login', 'Auth\LoginController@login');
Route::post('logout', 'Auth\LoginController@logout')->name('logout');
Route::group(['middleware' => 'auth'], function () {
/*

33
tests/Feature/Cart/SearchProductsTest.php

@ -0,0 +1,33 @@
<?php
namespace Tests\Feature\Cart;
use App\Product;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Tests\TestCase;
class SearchProductsTest extends TestCase
{
use DatabaseMigrations;
/** @test */
public function retrieving_product_list_by_ajax_post_request()
{
$this->disableExceptionHandling();
factory(Product::class)->create(['name' => 'Hemaviton']);
factory(Product::class)->create(['name' => 'Zee']);
$product1 = factory(Product::class)->create(['name' => 'Bisolvon 1']);
$product2 = factory(Product::class)->create(['name' => 'Bisolvon 2']);
$user = $this->loginAsUser();
$response = $this->post(route('api.products.search'), ['query'=> 'Bis']);
$response->assertSuccessful();
$response->assertJsonFragment([
'name' => 'Bisolvon 1',
'name' => 'Bisolvon 2',
]);
}
}

16
tests/TestCase.php

@ -4,6 +4,8 @@ namespace Tests;
use App\User;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use App\Exceptions\Handler;
use Illuminate\Contracts\Debug\ExceptionHandler;
abstract class TestCase extends BaseTestCase
{
@ -16,4 +18,18 @@ abstract class TestCase extends BaseTestCase
return $user;
}
protected function disableExceptionHandling()
{
// Disable Laravel's default exception handling
// and allow exceptions to bubble up the stack
$this->app->instance(ExceptionHandler::class, new class extends Handler {
public function __construct() {}
public function report(\Exception $exception) {}
public function render($request, \Exception $exception)
{
throw $exception;
}
});
}
}
Loading…
Cancel
Save