When creating a SmartCollection, how do we get the user to click through to a specific relation like the generated collections?
E.g. clicking on a record below, or even the artist ‘name’ I want to take the user to that artist record. The relations all exist but not sure that the smartcollection is aware of it - how do I declare the relationship?
The docs specify how to do this in SQL and MongoDB but not using Laravel implementation:
Also, I’ve tried ‘artist.id’ as the reference as this is what the underlying class is in the forest schema and at /data/artist/index, but then returns this console error
Not sure where I’m going wrong here, the Artist model is a real database model, the artistList is the virtual forestadmin collection.
I’ve noticed that the documentation for the collection has the model extending SmartCollection, but then in the smartRelationship documentation it extends Model? Since we can’t have both in PHP is it meant to be model?
The below returns
Base table or view not found: 1146 Table '2023_01_12.artist_lists' doesn't exist
But can only assume this is because I’ve switched the extends decleration from the SmartCollection class to Model class.
If I use SmartCollection now, to how it was working before, I get
"Return value of ForestAdmin\\LaravelForestAdmin\\Http\\Controllers\\ResourcesController::getModel() must be an instance of Illuminate\\Database\\Eloquent\\Model, instance of App\\Models\\SmartCollections\\ArtistList returned"
namespace App\Models\SmartCollections;
use App\Models\Artist;
use Illuminate\Support\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use ForestAdmin\LaravelForestAdmin\Services\SmartFeatures\SmartField;
use ForestAdmin\LaravelForestAdmin\Services\Concerns\ForestCollection;
use ForestAdmin\LaravelForestAdmin\Services\SmartFeatures\SmartCollection;
use ForestAdmin\LaravelForestAdmin\Services\SmartFeatures\SmartRelationship;
class ArtistList extends Model
{
use HasFactory, ForestCollection;
protected string $name = 'artistList';
protected bool $is_searchable = true;
protected bool $is_read_only = true;
/**
* @return SmartRelationship
*/
public function artist(): SmartRelationship
{
return $this->smartRelationship(
[
'type' => 'Number',
'reference' => 'artists.id'
]
)
->get(
function () {
return Artist::where('id', $this->id)
->first();
}
);
}
Since this is not a Laravel model, I confirm that it must extend from SmartCollection.
Given the error, I assume it is a route conflict.
Have you implemented the routes for this Smartcollection in a custom controller and in web/routes.php?
More information : here