Route::get('/personas/{idPersona}/quotes', 'QuoteController@index');
QuoteController.php:
public function index($id)
{
$quotes = Quote::where('idPersona', $id)->get();
return View::make('quotes.index')->with('quotes', $quotes);
}
views/quotes/index.blade.php:
<h2> Quotes </h2>
@foreach($quotes as $quote)
<li>{{ $quote }}</li>
@endforeach
models/Quote.php
class Quote extends Eloquent {
public $timestamps = false;
protected $table = 'quote';
protected $primaryKey = 'idquote';
}
models/Persona.php
class Persona extends Eloquent {
public $timestamps = false;
protected $table = 'persona';
protected $primaryKey = 'idPersona';
}
I have 2 tables, Persona and Quote, and I am trying to pull all the quotes that match the foreign key idPersona:
CREATE TABLE `mountain`.`persona` (
`idPersona` INT NOT NULL AUTO_INCREMENT,
`fName` VARCHAR(45) NULL,
`lName` VARCHAR(45) NULL,
`mName` VARCHAR(45) NULL,
`bio` TEXT NULL,
`dateBorn` VARCHAR(45) NULL,
`dateDied` VARCHAR(45) NULL,
PRIMARY KEY (`idPersona`));
CREATE TABLE `mountain`.`quote` (
`idquote` INT NOT NULL AUTO_INCREMENT,
`quoteText` TEXT NOT NULL,
`quoteSource1` VARCHAR(100) NULL,
`quoteSource2` VARCHAR(100) NULL,
`tag1` VARCHAR(45) NULL,
`tag2` VARCHAR(45) NULL,
`tag3` VARCHAR(45) NULL,
`idPersona` INT NULL,
PRIMARY KEY (`idquote`),
INDEX `idPersona_idx` (`idPersona` ASC),
CONSTRAINT `idPersona`
FOREIGN KEY (`idPersona`)
REFERENCES `mountain`.`persona` (`idPersona`)
ON DELETE NO ACTION
ON UPDATE NO ACTION);
implements UserInterface, RemindableInterface
和use UserTrait, RemindableTrait;
仅适用于User
类。 - peter.babic