How to Get API with Parameter.? Go to the Controller and create the Method. function listparam ( $id = null ) { return ClientModel :: find($id) ; } Now also change the API Routes Route :: get( "lists/{id}" , [ DBController :: class , 'listparam' ] ) ; Now OutPut Result
How to get data with API.? 1. Step Go Terminal php artisan make:migration create_abc_table Press Enter Create Table 2. Step go Terminal php artisan migrate 3. Step Check Database 4. Step Let's start get data with API Create the Controller go Terminal php artisan make:controller DBController // Get data with API form DB function list () { return ClientModel :: all() ; } 5. Step Create the Model go Terminal php artisan make:model ClientModel class ClientModel extends Model { use HasFactory ; protected $table = 'clientmodel' ; protected $fillable = [ 'name' , 'email' , 'address' ]; } 6. Step go routes and create the route Route :: get( "lists" , [ DBController :: class , 'list' ] ) ; Output:
Comments
Post a Comment