Laravel blade template name from database - laravel

I have a master blade file which will include another blade file based on a DB value like so:
#include('sign/templates/{{$SignRequest->form_template}}')
The db field form_template contains the name of the blade file to include. This name is passed to the master blade file correctly, but I can't figure out how to use this value within the include statement.
I get the following error:
View [sign.templates.<?php echo e($SignRequest->form_template); ?>] not found.

#include('sign.templates.'.$SignRequest->form_template)

Related

Retrieving a single value from belongsToMany relationship in blade template

I have created a model with a belongsToMany relationship. The model is Vendor and the relationship with Location. So, in my blade template, I would normally do something like this:
#foreach ($vendor->locations as $loc)
{{$loc-id}}
#endforeach
However, I would like to simply json_encode only the id values for each of the locations. If possible, I would like to do so without creating a loop. So, I know I can do this:
{{json_encode($vendor->locations)}}
But as you can guess, this dumps out JSON data of all of the fields in the locations table.
I know I can modify my relationship to only include the ID fields, but I do not want to do this because I want to use the relationship elsewhere.
Is there a way to just grab the ID fields using something like:
{{json_encode($vendor->locations->id)}}
You can pluck the 'id' and convert it directly to json.
{{ $vendor->locations->pluck('id')->toJson() }}
This requires that $vendor->locations is a Collection.
You can use Laravel's pluck and json methods:
{{ $vendor->locations->pluck('id')->toJson() }}
You can refer to the documentation for more information:
https://laravel.com/docs/8.x/collections#method-tojson

Use tables prefix for spatie/laravel-tags tables

In my Laravel 5.7 app, I use spatie/laravel-tags: ^2.1. I need to use a prefix for table names and I set table property of any model with prefix and with empty prefix property in config/database.php. It works for my model, except the tag model,
when I use method findOrCreate from Spatie\Tags\Tag.
I got error that table “tags” not found, as my prefix is not set.
If there is a way to set this prefix(config options?) ?
sure decision without modifications of vendor/spatie/laravel-tags/src/Tag.php file preferable...
Thanks!

Laravel view not displaying long number correctly

I have a column name xxx in database. it is of type varchar(255). It is storing 9006686769394. I access its value and store it in a variable named $refCode. When I do {{ $refCode }} in laravel view, it displays like this: 9.00668676939E+12. Why can't I display the variable properly ? Any suggestion ?

Saving Extension Config Data Magento

I've been trying to figure out exactly how does magento save the config data for a module given in System.xml. reason?I would like to edit the data provided by the user before storing it in the database.
Any clues????
Take a look at Mage_Core_Model_Store::setConfig function (and getConfig for reading the value). You will probbably have to write an observer that will listen to store_save_before event.
Magento stores configuration data in core_config_data database table - path column is the hierarhical structure of XML elements in system.xml file and is the same as XPath used for reading the default value out of config.xml file and value column contains the value that was saved.
When accessing the data with for e.g. Mage::getStoreConfig( 'path', $storeId ); Magento first searches the table for path-value pair and if it doesn't find it it reads the default value from config.xml file.

CodeIgniter dynamic database in database.php

I want to change a variable in database.php to be dynamic. I want to create a field to get a value and then pass it into a variable in database.php instead.
You could always modify the database.php file via http://www.tizag.com/phpT/filewrite.php

Resources