daniel
daniel
TCTwill CMS
Created by daniel on 2/7/2024 in #👊support
InlineRepeater deleting data on related Model entries
I'm using an InlineRepeater to add relations with pivot data between two Repositories. The relations and pivot data are being stored as expected, but I just realized that when I update the entry, it is also deleting Media and Block data for the related model entry. I just lost a good bit of work to this. I have a repository Location and a repository Taxa, with a location_taxa many-to-many pivot table to connect the two. In the Taxa model, I've created this relation:
public function locations(): BelongsToMany
{
return $this->belongsToMany(Location::class)
->orderByPivot('position')
->withPivot(['details']);
}
public function locations(): BelongsToMany
{
return $this->belongsToMany(Location::class)
->orderByPivot('position')
->withPivot(['details']);
}
In my TaxaController, I've configured the InlineRepeater as such:
Fieldset::make()->title('Locations')->id('locations')->fields([
InlineRepeater::make()
->name('location_taxa')
->label('Locations')
->allowBrowser()
->relation(Location::class)
->fields([
Input::make()
->name('title')
->translatable()
->disabled(),

Wysiwyg::make()
->name('details')
->translatable()
,

]),
]),
);
Fieldset::make()->title('Locations')->id('locations')->fields([
InlineRepeater::make()
->name('location_taxa')
->label('Locations')
->allowBrowser()
->relation(Location::class)
->fields([
Input::make()
->name('title')
->translatable()
->disabled(),

Wysiwyg::make()
->name('details')
->translatable()
,

]),
]),
);
This stores the relationship and details in the pivot table as expected. I'm not sure why it's also accidentally destroying the data
17 replies
TCTwill CMS
Created by daniel on 1/2/2024 in #👊support
DatePicker Exception
I'm getting an unexpected error while using a pretty simple DatePicker in my sidebar form. Undefined variable $formFieldsValue (View: /app/vendor/area17/twill/views/partials/form/_date_picker.blade.php) In my form:
<x-twill::date-picker
name="sale_starts_at"
label="Sale Starts"
:translated="true"
/>
<x-twill::date-picker
name="sale_starts_at"
label="Sale Starts"
:translated="true"
/>
The fields exist and are in $fillable and in the $translatedAttributes . Not sure what I'm doing wrong here.
3 replies
TCTwill CMS
Created by daniel on 5/9/2023 in #👊support
Updating Translations from the Command Line
Hi all, as usual I assume I'm misunderstanding something basic about how Laravel works, but I have been stuck trying to update existing translations directly with data from a Console Command. I'm trying to back-fill some missing information that I'm scraping from HTML files. I have tried several different combinations of querying the database to get the existing record and updating it, but nothing seems to work. I can verify that the entry I'm trying to update exists in the database, but when I try to update() or save() I just don't get any results, and don't get any errors. This is my current attempt to query out the existing entries. Not sure how to update the model that this returns.
$existingProduct = Product::join('product_translations', 'products.id' , '=', 'product_translations.product_id')
->where('title', $productTitle)
->where('locale', 'en')
->where('products.deleted_at', null)
->where('product_translations.deleted_at', null)
->where('brand_id', $brandId)
->first();
$existingProduct = Product::join('product_translations', 'products.id' , '=', 'product_translations.product_id')
->where('title', $productTitle)
->where('locale', 'en')
->where('products.deleted_at', null)
->where('product_translations.deleted_at', null)
->where('brand_id', $brandId)
->first();
4 replies
TCTwill CMS
Created by daniel on 2/8/2023 in #👊support
Sorting by a translation field (ie, title)
Hi everyone, I feel like I must be missing something simple (as usual) or am making something overly complicated when trying to sort a query by my title translation field. I have a Product model that is linked to my Brand model via a brand_id field, with the relationship in the Product model as follows:
public function brand()
{
return $this->belongsTo(\App\Models\Brand::class);
}
public function brand()
{
return $this->belongsTo(\App\Models\Brand::class);
}
When I try to get the Products for a Particular brand, things start breaking. I had this query, but it breaks things on the front end, the id field gets overridden and breaks the relationships to translations, I can't use slugs, etc.
$brandProducts = Product::where('brand_id', '=', $brand->id)
->join('product_translations', 'product_id','=', 'products.id', 'inner')
->orderBy('title', 'asc')->get();
$brandProducts = Product::where('brand_id', '=', $brand->id)
->join('product_translations', 'product_id','=', 'products.id', 'inner')
->orderBy('title', 'asc')->get();
I feel like I am doing something obviously wrong here and I shouldn't have to keep adding more and more JOINs to get the fields I need to make this work properly. I suspect that I'm still relatively new to Laravel may be coming into play here as well. Is there an easier way to query using a field (brand_id) and still have access to sorting via some of the "default" Repository associations like translations and slugs?
6 replies
TCTwill CMS
Created by daniel on 11/22/2022 in #👊support
Naming many-to-many tables in Twill and Laravel
Hi everyone! This may ultimately be more of a Laravel question than a Twill question, but any help is appreciated. I have a repository products and a repository reviews. I wanted to link these , so created a repository I named productReviews.
The migrations are created with the name product_reviews and that migration logic is expecting me to use that name (when I try to change it to singular, the migration would fail). When I try to use that table in the CMS something in Twill/Laravel is expecting the name of the table to be product_review (singular). So I end up having to manually change the name of the table after running the migration. Obviously this doesn't seem quite right. What am I missing? Should the original repository creation have been productReview instead of productReviews ?
16 replies
TCTwill CMS
Created by daniel on 11/14/2022 in #👊support
Issue with locales and creating model records from a custom page
14 replies
TCTwill CMS
Created by daniel on 11/2/2022 in #👊support
Searching via tags
I feel like I might be overlooking something simple, but I'm using the HandleTags trait on my module's repository (PostRepository) to use tagging. I can get the tags for each Post just fine, but I'm not sure how to search for Posts via a tag slug. Any suggestions?
3 replies