Get Blank Data From Api Even Data Is Available For Fetch In Database

- 1 answer

Hello Guys nowadays am working on laravel project and in this project i have make 2 api one is working perfectly like i am getting all the data from database accurately but in the second api i am getting blank data means nothing both api is same but just from one api am getting data from ID and in second api i am getting data from email please help me.

it is my api.php code


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();
// routes/api.php
// POST /api/post?api_token=UNIQUE_TOKEN
Route::post('post', 'Api\[email protected]')->middleware('auth:api');
Route::get('/getemail/"{email}"','[email protected]');

and it's my EmailController Code


namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\email;

class EmailController extends Controller
    public function databyemail($email){

    $data = new email();

    $data = email::find($email);

    return response()->json($data);
and finally it is my email model code


namespace App;

use Illuminate\Database\Eloquent\Model;

class email extends Model
    protected $table = 'users';
    protected $fillable = ['surname','first_name','last_name','username','email','password','language','contact_no','address','remember_token','business_id','status'];

please help me why i am getting nothing from database

Thanks in Advance



I think you should fix your Route, you don't need to use " " marks for the variables.

Route::get('/getemail/{email}','[email protected]');

Just use like this.

Also, find works with Primary key so,

Instead of:

$data = email::find($email);


$data = email::where('email', $email)->first();