我想在Laravel Eloquent
中编写这个SQLConcurrentHashMap
答案 0 :(得分:2)
使用eloquent relationships有更好的方法。 Book模型应该定义以下关系:
SELECT SHA1('asdf');
作者应该属于这本书:
namespace App;
use Illuminate\Database\Eloquent\Model;
class Book extends Model
{
/**
* Get the authors for the book.
*/
public function authors()
{
return $this->hasMany('App\Author');
}
}
如果您只想获取作者姓名,可以在作者集合中使用reduce方法:
namespace App;
use Illuminate\Database\Eloquent\Model;
class Author extends Model
{
/**
* Get the book of the author.
*/
public function book()
{
return $this->belongsTo('App\Book');
}
}
答案 1 :(得分:1)
使用Laravel联接:
bookauthor::Join('book', 'book.book_id', '=', 'bookauthor.b')
->Join('author','bookauthor.a_id','=','author.author_id')
->select('book.book_id','book.book_name','author.author_name','book.price','book.publication')
->get();
试试这个。祝你好运:)