Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Dependent dropdown in Laravel5 PHP. For full article check here http://josephrex.me/implementing-dynamic-drop-down-or-dependent-list-in-laravel4
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Category extends Model{
public function subcategories(){
return this->hasMany('App\Subcategory')
}
}
<?php
use App\Category;
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class CategoryController extends Controller{
public function api(Request $request){
$input = $request->input('option');
$category = Category::find($input);
return response()->json($category->subcategories);
}
}
<?php
Route::get('api/dropdown', [
'uses' => 'CategoryController@api',
'as' => 'category_api'
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.