Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Database 从api获取空白数据,即使数据可用于在数据库中提取_Database_Laravel_Api_Controller_Fetch - Fatal编程技术网

Database 从api获取空白数据,即使数据可用于在数据库中提取

Database 从api获取空白数据,即使数据可用于在数据库中提取,database,laravel,api,controller,fetch,Database,Laravel,Api,Controller,Fetch,大家好,我现在正在从事laravel项目,在这个项目中,我制作了2个api,其中一个工作得非常完美,就像我从数据库中准确地获取所有数据一样,但在第二个api中,我获取的空白数据意味着两个api都不相同,只是从一个api中,我从ID获取数据,在第二个api中,我从电子邮件获取数据,请帮帮我 这是我的api.php代码 <?php use Illuminate\Http\Request; /* |-----------------------------------------------

大家好,我现在正在从事laravel项目,在这个项目中,我制作了2个api,其中一个工作得非常完美,就像我从数据库中准确地获取所有数据一样,但在第二个api中,我获取的空白数据意味着两个api都不相同,只是从一个api中,我从ID获取数据,在第二个api中,我从电子邮件获取数据,请帮帮我

这是我的api.php代码

<?php

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\PostController@store')->middleware('auth:api');
Route::get('/getemail/"{email}"','EmailController@databyemail');


and it's my EmailController Code

<?php

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

<?php

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'];
}

我认为您应该修复您的路由,您不需要为变量使用“”标记

Route::get('/getemail/{email}','EmailController@databyemail');
就这样用吧

另外,查找主键的工作,因此

而不是:

$data=email::find($email)

使用:


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

$data=email::find($email);您正在使用$email进行查找,您只能使用find中的主键,而可以使用,
$data=email::firstWhere('email',$email)亲爱的当我写$data=email::firstWhere('email',$email);并删除$data=email::find($email);所以我得到的错误是500,然后尝试,
$data=email::where('email',$email)->first()谢谢亲爱的,它工作起来很有魅力谢谢你这么多你让我忙了那么多关于这个问题我还有一个问题你能回答我这个问题吗,或者我需要创建一个新的问题