Why not display ajax sorting?

Decided to make the ajax sorting on this video.

Has created 2 models is a "Category" and "category", called them "Category" and "Subcategory".
Both inscribed in it:

protected $fillable = ['name'];

There is a controller named ProductController in the method index() is written this:
public function index()
 $categories = Category::all();
 $allProducts = Product::all();
 $productsPagination = Product::paginate(4);

 return view('index', compact('allProducts', 'productsPagination', 'categories'));

This is my main controller, which works with products.

All my routers:

Route::get('/', function() {
 $categories = App\Category::all();

 return view('index', ['categories' => $categories]);

Route::get('/ajax-subcat', function() {
 $cat_id = Input::get('cat_id');

 $subcategories = Subcategory::where('category_id', '=', $cat_id)->get();

 return Response::json($subcategories);

Route::get('/', 'ProductController@index');

Resource('product', 'ProductController');

Yourself ajax code:

$(document).ready(function() {
 $('#category').on('change', function(e) {
 var cat_id = e.target.value;

 $.get('/ajax-subat?cat_id=' + cat_id, function(data) {

 $.each(data,function(index, subcatObj) {
 $('#subcategory').append('<option value="'+subcatObj.id+'">'+subcatObj.name+'</option>');

But do the selectors to sort:
Here be output the category title from the database:
{{ Form::open(array('url' => ", 'files' => 'true')) }} <div class="col-lg-6 col-md-6 col-xs-4"> <div class="form-group"> <label for>Categories</label> <select class="form-control input-sm" name="category" id="category"> @foreach($categories as $category) <option value="{{ $category->id }}">{{ $category->name }}</option> @endforeach </select> </div> </div>

Here is ajax'ω is displayed under the category.
<div class="col-lg-6 col-md-6 col-xs-4">
 <div class="form-group">
 <label for>Subcategories</label>
 <select class="form-control input-sm" name="subcategory" id="subcategory">
 <option value></option>
{{ Form::close() }}

Migration Categories table:
public function up()
 Schema::create('categories', function(Blueprint $table) {

Migration table Subcategories:
public function up()
 Schema::create('subcategories', function(Blueprint $table) {


On the main page when you select a main category displays this error:

PS what is the reason? Where to drip? Where to disassemble.
July 9th 19 at 14:05
2 answers
July 9th 19 at 14:07
Typo. ajax subat (in javascript) - ajax-subcat (in the router)
Thank you, corrected. Now gives another error s008.radikal.ru/i303/1605/3c/73a09d4ce5df.png - Jo_Schowalter commented on July 9th 19 at 14:10
See the error_log, there should be a description of the error. - Daphne_Roob commented on July 9th 19 at 14:13
: Where are these logs? - Jo_Schowalter commented on July 9th 19 at 14:16
On the server, whoever's in the execution of the queries involved, probably apache then /var/log/httpd/ - Daphne_Roob commented on July 9th 19 at 14:19
Or wait, specialists in Laravel will catch up, maybe by code once the problem is defined. - Daphne_Roob commented on July 9th 19 at 14:22
: The server is empty - Jo_Schowalter commented on July 9th 19 at 14:25
In config/app, set 'debug' to true and open a browser to localhost:8000/ajax-subcat?cat_id=2 - Amani_Greenho commented on July 9th 19 at 14:28
July 9th 19 at 14:09
Of course you need this link - X-CSRF-TOKEN
The issue is already decided) - Jo_Schowalter commented on July 9th 19 at 14:12

Find more questions by tags AJAXLaravelPHP