Tôi cố gắng để có được dữ liệu cụ thể từ cơ sở dữ liệu bằng cách sử dụng cột SongID
khi người dùng nhấp vào một liên kết nhưng tôi nhận được lỗi này:SQLSTATE [42S22]: Cột không tìm thấy: 1054 Unknown cột 'id' trong 'mệnh đề where' (SQL: select * từ `songs` nơi 'id` = 5 giới hạn 1)
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'where clause' (SQL: select * from
songs
whereid
= 5 limit 1)
Controller class:
<?php namespace App\Http\Controllers;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use DB;
class SongsController extends Controller {
public function index()
{
$name = $this->getName();
$songs = DB::table('songs')->get();
return view('songs.index', compact('songs','name'));
}
public function show($id)
{
$name = $this->getName();
$song = DB::table('songs')->find($id);
return view('songs.show', compact('song','name'));
}
private function getName()
{
$name = 'Tupac Amaru Shakur';
return $name;
}
}
Migration:
public function up()
{
Schema::create('songs', function($table)
{
$table->increments('SongID');
$table->string('SongTitle')->index();
$table->string('Lyrics')->nullable();
$table->timestamp('created_at');
});
}
như thế nào schema bảng của bạn trông như thế nào? Rõ ràng, bạn dường như thiếu một 'cột id' trong bảng của bạn vì một lý do .... – silkfire
Tôi không có một cột gọi là id trong bảng của tôi, thay vào đó tôi có SongID – Tartar