Laravel nova multiselect edit not working - laravel-5

I'm using laravel nova for creating an admin panel. This is my code.
Laravel nova resource,
use Nova\Multiselect\Multiselect;
public function fields(Request $request)
{
return [
ID::make()->sortable(),
Multiselect::make(__('Day'),'day')
->options($this->getweedkDay()),
];
}
private function getweedkDay(){
$weekDay = [];
$weekDay[1] = __('Sunday');
$weekDay[2] = __('Monday');
$weekDay[3] = __('Tuesday');
$weekDay[4] = __('Wednesday');
$weekDay[5] = __('Thursday');
$weekDay[6] = __('Friday');
$weekDay[7] = __('Saturday');
return $weekDay;
}
I'm using this plugin for multi select and date field is a varchar field in database. The issue is even I can select items and save them in db they will not be able to see in edit view or index view for nova resource. it would be great if someone can help

Use this package instead it's more mature and maintained as well:
https://github.com/optimistdigital/nova-multiselect-field

Related

Store a object directly on ORM Laravel?

I search for all the web and don't find a solution other than a custom function that we must make. I develops in Node.js and Laravel backend applications.
And in Node.js we send a object exactly equal to the database columns and we just use Sequelize insert function like this:
async store(model) {
try {
await this.model.city.create(model);
} catch (error) {
throw error;
}
}
We simply use the same object that sending from the app we store like this store(object); and works fine.
In Laravel I always must reference the columns even so the objects have the same attributes from the columns on database, like this:
$categoryObj = new Category;
$categoryObj->name = $category['name'];
$categoryObj->save();
return $categoryObj;
I want to just make something like this:
$categoryObj = new Category;
$categoryObj = $category;
$categoryObj->save();
return $categoryObj;
It is possible?
You can use the create method to insert a new record in the database.
class Category extends Model
{
protected $table = 'table_name';
protected $fillable = ['column_name_1', 'column_name_2', ...];
}
Then for inserting new data:
Example:
$model = YourModel::create([
'field' => 'value',
'another_field' => 'another_value'
]);
In your controller:
$categoryObj = new Category::create($category);
Also, you should look to Laravel's documentation: https://laravel.com/docs/5.8/eloquent#mass-assignment

How can I pass image file from Laravel to Express using Graphql?

I have a laravel project and my goal is to pass an image file from laravel to my express project, so that my graphql can save the name of my image file after
successfully renaming the image and uploading it in my express project.
At the moment, I am using \Softonic\GraphQL to query data from my express project. Example:
public function getUsers()
{
$client = \Softonic\GraphQL\ClientBuilder::build('http://localhost:3002/graphql');
$query = '
query GetUsers($sort:[[String!]!]!){
users(perPage:10, page: 1, sort: $sort){
users{
email
}
}
}
';
$var = [
'sort' => "email"
];
$response = $client->query($query, $var);
return $response->getData();
}
How should i implement it when uploading an image ? my current code looks like this ..
public function updateImg(Request $request)
{
$client = \Softonic\GraphQL\ClientBuilder::build('http://localhost:3002/graphql');
$query = '
mutation updateImage(id:ID!, $image: Upload!){
updateImage(id:1, image: $image){
users{
email
}
}
}
';
$var = [
'image' => $request->file('uploadImg');
];
$response = $client->query($query, $var);
return $response->getData();
}
On my express, when i inspect my image in console.log(), it returns empty.
I am not sure if the way im doing is correct or if it is even achievable.
One way to add support for uploading files to GraphQL is to add multipart form request support through this specification by Jayden Seric. He also provides an implementation project for certain environments. However, I have only tried and tested this with apollo-client and apollo-server-express.

Prestashop 1.7.5 module - Update SQL custom table

I'm trying to add a new module to my shop to manage the sql table's values that I made. I can't find a proper guide that show me how to do that because all the forms have values contained in ps_configuration and not within a custom table.
How can I show those values in my form and get to update them?
Thank you if you'll take the time to answer that ^^
So, my form fields are still blank and they don't update my table when I submit.
I added this to "_construct" function:
public function __construct() {
$this->id_sell = $id_sell;
$this->country = $country;
$this->p_cod = $p_cod;
and this to "getContent"
public function getContent() {
$sqlV = 'SELECT * FROM `'._DB_PREFIX_.'mytable` WHERE id_sell = 1';
if ($row = Db::getInstance()->getRow($sqlV))
$country = $row[country];
$p_cod = $row[p_cod];
and last this on "getConfigFormValues":
protected function getConfigFormValues()
{
return array(
'country' => Tools::getValue('country'),
'p_cod' => Tools::getValue('p_cod'),
);
}
So, now I know that a need a class ObjectModel {}, too. Working on it.. and hoping for the best :D

Laravel Sentry restrict Edit permissions to Creator

I am using Laravel to build a simple Movie management System.
When a User creates a Movie in my DB, I use the following
public function store()
{
$input = Input::except('_token');
$id = Helpers::loggedInUser()->id;
$input['creator_id'] = $id;
$this->title->create($input);
return Redirect::back()->withSuccess( trans('main.created successfully') );
}
This successfully passes the users id and stores in it a creator_id field
I want to restrict users from editing Movies which they did not create. So in the edit function I have
public function edit($title)
{
$title = $this->title->byURi( e($title) );
$id = Helpers::loggedInUser()->id;
$titleuser=$title['creator_id'];
if ( $titleuser = $id )
{
return View::make('Titles.Edit')->withTitle($title)->withType('movies');
}
}
However, this does not seem to work. Anyone with a movie.edit permission in my sentry user db can still see the view.
If you compare two variables you have to use two equal signs, otherwise you set the first variable to the value of the second.
if ( $titleuser == $id )

Order options in admin order view

Using
public function _prepareOptions(Varien_Object $buyRequest, $product, $processMode)
{
$options = parent::_prepareOptions($buyRequest, $product, $processMode);
$options['start_date'] = date here
$options['end_date'] = date here
return $options;
}
in my module I can save some custom options.
I can see them in the "sales_flat_quote_item_option" table.
What i'm stuck on is trying to retrieve and display these values with the order in the admin in this template
"app\design\adminhtml\default\default\template\sales\items\column\name.phtml"
Is there a way to get these options via the $_item variable in the template or will i need to use the orderid and models.
Still not sure which is the correct way but used the buyRequest object
public function prepareForCartAdvanced(Varien_Object $buyRequest, $product = null, $processMode = null)
{
$buyRequest->setData('start_date', $start);
}
Then in the view,
$_item->getBuyRequest()->getData('start_date');

Resources