Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Dependent dropdown in Laravel5 PHP. For full article check here
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Category extends Model{
public function subcategories(){
return this->hasMany('App\Subcategory')
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);
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.