我的表用户 - >
Schema::create('mstanggota', function (Blueprint $table) {
$table->increments('id');
$table->string('no_anggota',10);
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
表Mstbeasiswas - >
Schema::create('mstbeasiswas', function (Blueprint $table) {
$table->increments('id');
$table->string('no_anggota',10)->unique();
$table->string('nm_anak',25);
$table->string('kt_lahir',25);
$table->date('ttl');
$table->String('nm_skl',50);
$table->String('st_pend',6);
$table->String('lbg_pend',6);
$table->String('prov_skl');
$table->String('jenkel',9);
$table->integer('k_umum');
$table->integer('k_khusus');
$table->integer('score')->nullable();
$table->boolean('status')->default(0);
$table->string('ket',250)->nullable();
$table->string('img1',50)->nullable();
$table->string('img2',50)->nullable();
$table->string('img3',50)->nullable();
$table->timestamps();
});
我想尝试使用控制器显示数据,代码如下:
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Auth;
use App\Mstbeasiswa;
use App\User;
use Illuminate\Http\Request;
use App\Http\Requests;
use Illuminate\Database\Query\Builder;
class BeasiswaController extends Controller
{
public function index(){
/*$datas = Mstbeasiswa::orderBy('id','DESC')->paginate(1);
return view('home')->with('datas', $datas);
*/
$user = Auth::user()->no_anggota;
$user = Mstbeasiswa::table('mstbeasiswas')->where('no_anggota', $user)->first();
echo $user->no_anggota;
}
}
myerror - &gt;
Builder.php第2405行中的BadMethodCallException: 调用未定义的方法Illuminate \ Database \ Query \ Builder :: table()
帮助meee :(
答案 0 :(得分:1)
假设您创建了一个扩展Model类的Eloquent模型,您可以删除::table(...)
部分并调用
Mstbeasiswa::where('no_anggota', $user)->first();
但这只会给你一个型号。如果您需要集合,请使用->get()
代替->first()
,如下所示:
Mstbeasiswa::where('no_anggota', $user)->get();