malhayek

Experience

25,580

0 Best Reply Awards

  • Member Since 2 Years Ago
  • 180 Lessons Completed
  • 22 Favorites

9th July, 2017

malhayek left a reply on How Can I Include Bootstrap-datetimepicker In My Mix Setup? • 2 weeks ago

Thanks for the tip about the available download for node.js.

But, does that means I can't include a package that does not have node.js installer?

Also, how can I include the package's css file into my own app.sass class? how do I include it?

8th July, 2017

malhayek started a new conversation How Can I Include Bootstrap-datetimepicker In My Mix Setup? • 2 weeks ago

I need to include bootstrap-datetimepicker into my Mix setup. https://github.com/Eonasdan/bootstrap-datetimepicker

The bootstrap-datetimepicker package does not offer Node.js installer. How can I include it in my project?

Here is what I tried, I added a folder resources/assets/vendors and manually download the https://github.com/Eonasdan/bootstrap-datetimepicker in to it.

Then in my resources/assets/app.sass the following line

@import "node_modules/bootstrap-sass/assets/stylesheets/bootstrap";

But i am getting the following error when compiling the assets using npm run watch

Module build failed: ModuleNotFoundError: Module not found: Error: Can't resolve
 './resources/assets/vendors/bootstrap-datetimepicker-4.17.47/build/css/bootstra
p-datetimepicker.css' in 'resources\assets\sass' at factoryCallback (node_modules\webpack\lib\Compilation.js:260:39)

28th June, 2017

malhayek left a reply on How Can I Set Default Value With Form::selectRange And Form::selectMonth? • 4 weeks ago

How would Form::hidden allows me to set the default value for Form::selectMonth or Form::selectRange?

27th June, 2017

malhayek started a new conversation How Can I Set Default Value With Form::selectRange And Form::selectMonth? • 1 month ago

I am trying to use Laravel-Collective (https://laravel.com/docs/5.4/authentication#protecting-routes)

When using checkbox I am doing this to check if there is an older value then set the it otherwise use the default. Then I am using isset($biography->colors) to know if this is an edit request or not. if isset($biography->colors) true I'll set its value.

        <label for="colors_white" class="checkbox-inline">
            {!! Form::checkbox('colors[]', 'White',  (in_array('White', old('colors', isset($biography->colors) ? $biography->colors : ['White','Red'])) ? true : null) , ['id' => 'colors_white', 'class' => 'required' ]) !!}
            White
        </label>

How can I do the same thing with Form::selectRange and Form::selectMonth?

25th June, 2017

malhayek started a new conversation What Validation Rule So I Use To Validate The Length Of A String? • 1 month ago

I need to add a validation rule that restrict a string to be between 3 and 255 characters in length. This is a string not just a number.

I tried to use

required|digits_between:3,255

But the above is returning an error when i pass this string "This is a string test"

How can I validation the length of string?

19th June, 2017

malhayek left a reply on How To Redirect The User Back To The View With Error When The Controller Return Exception? • 1 month ago

@aydinbulut I know how to fix the error. In fact, I purposely generated the error by setting my $data variable to [] after the request was validated so I can write code to capture the errors.

All I want to do is go back to the same form the user was one. Then I want to show them a user friendly error. I don't really want to add global custom pages.

malhayek left a reply on How To Redirect The User Back To The View With Error When The Controller Return Exception? • 1 month ago

@Swapnil I think the main question here is how to trap these error so I can return a user friendly error.

flash does similar idea to `with('success_message','Message......')

my main problem is that the app still shows a full trace stack even when I used try/catch

malhayek started a new conversation How To Redirect The User Back To The View With Error When The Controller Return Exception? • 1 month ago

In some unexpected cases my controller would return exception. Instead of showing the user error trace, I want to show them a user friendly error instead. (query timeout, duplicate record or something at the database level)

Here is my method

    public function store(AssetCategoryFormRequest $request)
    {
        $data = $request->getData();
        
        AssetCategory::create($data);
        Session::flash('success_message', 'AssetCategory was added!');

        return redirect()->route('asset_categories.assetcategory.index');
    }

I am guessing one way would be by using try/catch block

    public function store(AssetCategoryFormRequest $request)
    {
        try {
            $data = $request->getData();
            
            AssetCategory::create($data);
            Session::flash('success_message', 'AssetCategory was added!');

            return redirect()->route('asset_categories.assetcategory.index');
        } catch(QueryException $e) {
            // But how to return to the same view and still pass an error message
            // I don't want to loose my request data also.


        }
    }

Is there a better way that using try/catch or is this the best way to go? How can I return the user back to the same view along with the request data and an error message?

26th May, 2017

malhayek started a new conversation What Is The Best Practice For Designing Site With Laravel? • 2 months ago

I need to write a system on the top of Laravel 5.4. This system needs to handle 2 languages.

I understand that Laravel has a built in handling for diffident locales. But what about routes? What is the best practice for such a system?

Do I prefix the my routes with the language key? How do I do that?

25th March, 2017

malhayek left a reply on How Can I Submit Code Improvement Of Laravel To Taylor? • 4 months ago

@clay So I forked the laravel/framework project. I made the changes and a commited/pushed my changed. My new code is now on my forked project on git hub.

Now, I want to submit my change for Taylor hoping he'll merge my code with the master branch.

I went to the original project (https://github.com/laravel/framework) and clicked on "New Pull Request" which sent me to this link https://github.com/laravel/framework/compare?expand=1

I am confused on which branch/tag to I pick and also how to I tell it to take my code and send it?

21st March, 2017

malhayek started a new conversation How Can I Call A Listener Outside The Score Of A Database Transaction? • 4 months ago

I have setup event and few listeners in my app which works well.

In my controller, I run all my code inside the score of a transaction. However, there is one listener that executes a query which I want it to be outside of the transaction scope. So it should be executed by itself and should not impact the transaction.

Is this something possible? How?

19th March, 2017

malhayek started a new conversation How Can I Submit Code Improvement Of Laravel To Taylor? • 4 months ago

I have a feature that I wish to add to Laravel which I think will help the community a lot.

I never contributed to someone else project and wish to do that this time.

How can I pull the development version of Laravel 5.5, add my code then send the change to Taylor hoping he will consider adopting this feature?

I am not very good with Git, so I would appreciate some help with the commands.

malhayek left a reply on What Is The Best Way To Handle The Datetime In Laravel? • 4 months ago

Thank you. What I ended up doing is creating a property that will auto manage this process for me. this is what I have done

in the config\app.php config file I added the following two lines.

    'fallback_in_format' => 'Y-m-d H:i:s',
    'fallback_out_format' => 'd/m/Y H:i A',

Then I created a new base class for my models like the following

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class BaseModel extends Model
{
    protected $fixedFormattedFields = null;

    /**
     * Get a plain attribute (not a relationship).
     *
     * @param  string  $key
     * @return mixed
     */
    public function getAttributeValue($key)
    {
        if( ($field = $this->getFieldToFormat($key)) != null)
        {
            return date($field['out_format'], strtotime($this->getAttributeFromArray($key)));
        }

        return parent::getAttributeValue($key);
    }

    /**
     * Set a given attribute on the model.
     *
     * @param  string  $key
     * @param  mixed  $value
     * @return $this
     */
    public function setAttribute($key, $value)
    {
        if( ($field = $this->getFieldToFormat($key)) != null)
        {
            $this->attributes[$key] = date($field['in_format'], strtotime($value));

            return $this;
        }

        return parent::setAttribute($key, $value);
    }
    
    /**
     * Get the format property for a given attribute on the model.
     *
     * @param  string  $key
     * @return mix (null|array)
     */
    protected function getFieldToFormat($key)
    {
        foreach($this->getFixedFormattedFields() as $field)
        {
            if($field['key'] == $key)
            {
                return $field;
            }
        }

        return null;
    }

    /**
     * Gets a fields to auto format.
     *
     * @return array
     */
    protected function getFixedFormattedFields()
    {
        if( is_null($this->fixedFormattedFields))
        {
            $this->fixedFormattedFields = [];

            if( property_exists($this, 'formattedDates') && is_array($this->formattedDates))
            {
                foreach($this->formattedDates as $field)
                {
                    if(!is_array($field))
                    {
                        $this->fixedFormattedFields[] = $this->getFixedFormattedField($field);
                        continue;
                    }

                    if(isset($field['key']))
                    {
                        $inFormat = isset($field['in_format']) ? $field['in_format'] : null;
                        $outFormat = isset($field['out_format']) ? $field['out_format'] : null;

                        $this->fixedFormattedFields[] = $this->getFixedFormattedField($field['key'], $inFormat, $outFormat);
                    }
                }
            }
        }

        return $this->fixedFormattedFields;
    }

    /**
     * Get get a standard format for the fields to auto format.
     *
     * @param  string  $key
     * @param  string $inFormat
     * @param  string $outFormat
     * @return array
     */
    protected function getFixedFormattedField($key, $inFormat = null, $outFormat = null)
    {
        return 
        [   
            'key' => $key,
            'in_format' => is_null($inFormat) ? config('app.fallback_in_format') : $inFormat,
            'out_format' => is_null($outFormat) ? config('app.fallback_out_format') : $outFormat
        ];
    }
}

Then in my model I do the following

<?php

namespace App\Models;

use App\Models\BaseModel;

class Expense extends BaseModel
{
    /**
     * Datetime attributes that should be auto manages
     *
     * @var array
     */
    protected $formattedDates = [
                                    [
                                     'key'        => 'paid_at',
                                     'in_format'  => 'Y-m-d H:i:s',
                                     'out_format' => 'd/m/Y H:i A'
                                    ],
                                    'starts_at',
                                    'ends_at'
                                ];

}

As you can see, now all I need to do is define the fields in the $formattedDates property. I can also specify the a different format for each property if I wish.

I hope this helps someone out there.

malhayek left a reply on Where Does Laravel Magically Handle The Mutator And Accessors? • 4 months ago

Thank you very much

malhayek left a reply on What Is The Best Way To Handle The Datetime In Laravel? • 4 months ago

I apologize, I am not following you. An example will be greatly appreciated.

malhayek started a new conversation Where Does Laravel Magically Handle The Mutator And Accessors? • 4 months ago

So Laravel uses reflection to look for an accessor or mutator method to apply custom logic when accessing a field or before saving the field in the database.

But, in what file in its code does it do this?

My guess is be by utilizing the php's own magic method __get() and __set(). I reviewed the Illuminate\Database\Eloquent class but, I don't see how in there Taylor is checking for the set*Attribute and get*Attribute pattern.

Where can I find the code that handles this?

malhayek left a reply on What Is The Best Way To Handle The Datetime In Laravel? • 4 months ago

@jlrdw I am trying to find a better way to handle the process of converting string to datetime and datetime to string on accessing or mutating the data without having to write 2 methods per field.

malhayek left a reply on What Is The Best Way To Handle The Datetime In Laravel? • 4 months ago

@jlrdw that link explains how to create helper methods. Are you saying to create a a global function two function to handle the conversion but still create a getter and setter for each field in each model?


function dateTimeToString($value)
{
    return date('d/m/Y  H:i A', strtotime($value));
}

function stringToDateTime($value)
{
    return date('Y-m-d H:i:s', strtotime($value));
}

Than my model will look like this

    /**
     * Mutate the paid_at to a valid date time
     *
     * @param  string  $value
     * @return void
     */
    public function setPaidAtAttribute($value)
    {
        $this->attributes['paid_at'] = stringToDateTime($value);
    }


    /**
     * Get the paid_at value.
     * @param  string  $value
     * @return string
     */
    public function getPaidAtAttribute($value)
    {
        return dateTimeToString($value);
    }

malhayek left a reply on What Is The Best Way To Handle The Datetime In Laravel? • 4 months ago

Corrent. If I understand you correctly, your saying to create a global getter and setter. this mean, I would need to hook into each model and for each field of the type datetime, apply a getter and a setter.

malhayek left a reply on What Is The Best Way To Handle The Datetime In Laravel? • 4 months ago

Are you saying that getter/setter is the best way to handle this?

How would I know the field type? How would create a global helper?

malhayek started a new conversation What Is The Best Way To Handle The Datetime In Laravel? • 4 months ago

I have models where I need to capture a datetime input from the user. Then I need to store it in the database, and then display it using the proper format.

I am currently handling the process of converting the customer input to a the correct for mat using a mutator. Also, I am using accessor to convert the format from database format to easier to read format.

This is my current code

    /**
     * Mutate the paid_at to a valid date time
     *
     * @param  string  $value
     * @return void
     */
    public function setPaidAtAttribute($value)
    {
        $this->attributes['paid_at'] = date('Y-m-d H:i:s', strtotime($value));
    }


    /**
     * Get the paid_at value.
     * @param  string  $value
     * @return string
     */
    public function getPaidAtAttribute($value)
    {
        return date('d/m/Y  H:i A', strtotime($value));
    }

What is the best way handle this process so I won't have to create a mutator and an accessor for each datetime field?

12th March, 2017

malhayek left a reply on What Is The Right Way To Package All JS And CSS File Under One File In Laravel 5.4? • 4 months ago

@vipin93 actually I missed an error. I am still getting an error in the command window when I run npm run watch

Here is that I get

 10% building modules 1/1 modules 0 active
Webpack is watching the files.

 95% emitting

 ERROR  Failed to compile with 1 errors                                                                                                                                                       3:37:10 PM


This dependency was not found:

* -!../../../node_modules/css-loader/index.js!./css/custom.css in ./~/css-loader!./~/postcss-loader!./~/resolve-url-loader!./~/sass-loader/lib/loader.js?{"precision":8,"outputStyle":"expanded","source
Map":true}!./resources/assets/sass/app.scss

To install it, you can run: npm install --save -!../../../node_modules/css-loader/index.js!./css/custom.css

malhayek left a reply on What Is The Right Way To Package All JS And CSS File Under One File In Laravel 5.4? • 4 months ago

@vipin93 I installed the package using npm install eonasdan-bootstrap-datetimepicker

Then in `resources/assets/sass/app.scss I added the followng line.

@import "node_modules/eonasdan-bootstrap-datetimepicker/src/sass/bootstrap-datetimepicker-build.scss";

Does that mean the package will be compiled are ready for me to use including its dependencies? do I need to manually download its dependencies?

Also, usually, to attach the plugin to an element I do something like this

$('.datetime-picker-c').datetimepicker();

Where do I place this code at to attach the plugin?

malhayek left a reply on What Is The Right Way To Package All JS And CSS File Under One File In Laravel 5.4? • 4 months ago

@ejdelmonico @Cronix this is what I have done trying to use moment.js and https://www.npmjs.com/package/eonasdan-bootstrap-datetimepicker

npm install moment npm install eonasdan-bootstrap-datetimepicker

Then I opened the/resources/assets/js/app.js file and added this window.moment = require('moment');

I am not sure if I am doing this right or not. also how do I include the eonasdan-bootstrap-datetimepicker package so it is compiled?

malhayek left a reply on What Is The Right Way To Package All JS And CSS File Under One File In Laravel 5.4? • 4 months ago

@vipin93 that fixed that error.

What is the correct way to install bootstrap drop-down menu package? http://eonasdan.github.io/bootstrap-datetimepicker/Installing/ using Laravel's out of the box setup?

malhayek left a reply on What Is The Right Way To Package All JS And CSS File Under One File In Laravel 5.4? • 4 months ago

Thanks for your help.

I am little confused on how to include external vendor packages. For example, I want to use this package http://eonasdan.github.io/bootstrap-datetimepicker/Installing/ this package hadependencies like jQuery (https://jquery.com/) and Moment (https://github.com/moment/moment)

How to I include these with a fresh Laravel 5.4 installation? Do I manually download the packages?

Finally, when I tried follow the documentation about the setup (https://laravel.com/docs/5.4/mix#introduction) I am running into an error.

I tried installing the dependencies using thenpm install command. then when I try to compiling my assets using npm run dev I get the following errors

> node node_modules/cross-env/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js

module.js:471
    throw err;
    ^

Error: Cannot find module 'C:\xampp\htdocs\Retailer\node_modules\cross-env\bin\cross-env.js'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:509:3

npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "dev"
npm ERR! node v6.9.1
npm ERR! npm  v3.10.8
npm ERR! code ELIFECYCLE
npm ERR! @ dev: `node node_modules/cross-env/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.
js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @ dev script 'node node_modules/cross-env/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/s
etup/webpack.config.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the  package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node node_modules/cross-env/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     C:\xampp\htdocs\Retailer\npm-debug.log


11th March, 2017

malhayek started a new conversation What Is The Right Way To Package All JS And CSS File Under One File In Laravel 5.4? • 4 months ago

I always manually included my js or css files into the layout. However, this time I'll like to learn the better method which is combining the JS and CSS files into a single file for the CSS and another for the JS.

I have used Gulp in the past with other languages like ASP.NET so I am familiar with the technique but would like to learn how to use this in Laravel project.

How do I include vendor JS project + custom JS code into one file in my Laravel 5.4 project?

17th February, 2017

malhayek left a reply on Carbon Issue When Compiling The Classes • 5 months ago

@Snapey yes I have the correct class name for my class and it is being called when it should but erroring when I callCorbon::now();

@SaeedPrez I did composer dump-autoload which did not help. However, I have two custom packages that I added to my psr-4 section of my composer.json

Here is how my autoload section looks like

    "autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\\": "app/",
            "Mycorp\\Surveys\\": "Mycorp/surveys/src",
            "Mycorp\\Ahold\\": "Mycorp/demo/src"
        }
    }

malhayek started a new conversation Carbon Issue When Compiling The Classes • 5 months ago

I am trying to use Carbon to update a field with Eloquent.

Here is what I have done. On the very top of my class I did

use \Carbon\Carbon;

Then to use eloquent to set the updated_at field,

$model->updated_at = Carbon::now();

This works fine until I try to compile the classes for production using the following command

php artisan compile

Because I am using the backslash in the use command the compiler is causing an error. I guess I am not supposed to be using the backslash. However, If I don't use the backslash get the following errors.

exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Class 'Carbon' not found' in .....

How can I use Carbon class and then compile my classes?

14th February, 2017

malhayek started a new conversation How To Use Eloquent Fluent To Update Records After Joining? • 5 months ago

I am trying to use fluent syntax with eloquent to achieve the same results as the below SQL query would achieve.

UPDATE g SET q.completed = q.completed + 1 FROM [groups] AS g INNER JOIN [quotas] AS q ON q.qid = g.qid WHERE g.iid = 12234

The groups table has a model called group. Also, the quotas table has a model called quota

What is the correct way to join the two model and increment the quota.completed property?

Note, each model point to a different database.

31st December, 2016

malhayek left a reply on Php Artisan Vendor:publish Is Not Doing Anything! • 6 months ago

yes I have. In fact, the composer.json file of that package does composer dumpautoload after the installation or update automatically.

malhayek left a reply on Php Artisan Vendor:publish Is Not Doing Anything! • 6 months ago

I tried that command but still same result. Yes the package has files to be publish. Look at the service provider.

Also look at this link https://github.com/CrestApps/laravel-code-generator or https://packagist.org/packages/crestapps/laravel-code-generator

malhayek started a new conversation Php Artisan Vendor:publish Is Not Doing Anything! • 6 months ago

I am trying to execute php artisan vendor:publish for a specific vendor. But the command keep giving me Nothing to publish for tag [].

I don't understand why this command does not give you better info.

Here is the exact command

php artisan vendor:publish --provider="CrestApps\\CodeGenerator\\CodeGeneratorServiceProvider"

I actually went into CrestApps\\CodeGenerator\\CodeGeneratorServiceProvider and var dumped a message in the boot() method and I got that message. So the correct service provider is being called.

This is the code from my service provider


<?php

namespace CrestApps\CodeGenerator;

use Illuminate\Support\ServiceProvider;

class CodeGeneratorServiceProvider extends ServiceProvider
{
    /**
     * Indicates if loading of the provider is deferred.
     *
     * @var bool
     */
    protected $defer = false;

    /**
     * Perform post-registration booting of services.
     *
     * @return void
     */
    public function boot()
    {

        $this->publishes([
            __DIR__ . '\\..\\config\\codegenerator.php' => config_path('codegenerator.php'),
        ]);

        $this->publishes([
            __DIR__ . '\\templates' => base_path('resources\\codegenerator-templates\\default'),
        ]);

    }

    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register()
    {
        $this->commands(
            'CrestApps\CodeGenerator\Commands\CreateControllerCommand',
            'CrestApps\CodeGenerator\Commands\CreateModelCommand',
            'CrestApps\CodeGenerator\Commands\CreateIndexViewCommand',
            'CrestApps\CodeGenerator\Commands\CreateCreateViewCommand',
            'CrestApps\CodeGenerator\Commands\CreateFormViewCommand',
            'CrestApps\CodeGenerator\Commands\CreateEditViewCommand',
            'CrestApps\CodeGenerator\Commands\CreateShowViewCommand',
            'CrestApps\CodeGenerator\Commands\CreateViewsCommand',
            'CrestApps\CodeGenerator\Commands\CreateLanguageCommand',
            'CrestApps\CodeGenerator\Commands\CreateFormRequestCommand',
            'CrestApps\CodeGenerator\Commands\CreateRoutesCommand',
            'CrestApps\CodeGenerator\Commands\CreateMigrationCommand',
            'CrestApps\CodeGenerator\Commands\CreateResourceCommand',
            'CrestApps\CodeGenerator\Commands\CreateViewLayoutCommand'
        );
    }
}


I validated that the file/folder that are being copied are correct and exists using scandir() and get_file_content()`

What could be causing this problem? why no files are being copied to the destination?

There is nothing in the laravel log file to also help me here.

30th December, 2016

malhayek left a reply on What Is The Best Laravel 5.1 Generator? • 6 months ago

This one is very flexible and has lots options

https://github.com/CrestApps/laravel-codegenerator

It also have detailed documentation

https://crestapps.com/laravel-code-generator/docs/1.0

26th December, 2016

malhayek started a new conversation How To Deplay Laravel Project On Shared Hosting With Out Changing The Project Folders? • 7 months ago

I am trying to deploy a new Laravel project on a shared hosting. I also would like to keep my Laravel project apps setup the same as if it was on my local machine "standard Laravel setup".

I used FileZilla to transfer all the files from my local machine to the web hosting.

so /public_html contains all of my laravel file and folders.

when I go to mydomain.com I get the provider's default page. and when I go to mydomain.com/public I get a white page.

How can I get laravel app to render when I go to mydomain.com?

25th December, 2016

malhayek started a new conversation What Is A Good Hosting Company? • 7 months ago

Can someone please lead me to a good hosting company where I can host few Laravel base project?

I am looking for a company to allow offer low cost SSL cert.

22nd December, 2016

malhayek left a reply on How Can I Register A New Language Key At Run Time With Laravel? • 7 months ago

The addLines method did the trick!

/**

  • Add translation lines to the given locale.
  • @param array $lines
  • @param string $locale
  • @param string $namespace
  • @return void / public function addLines(array $lines, $locale, $namespace = '') { foreach ($lines as $key => $value) { list($group, $item) = explode('.', $key, 2); Arr::set($this->loaded, "$namespace.$group.$locale.$item", $value); } }

21st December, 2016

malhayek started a new conversation How Can I Register A New Language Key At Run Time With Laravel? • 7 months ago

I wrote a script with Laravel 5.3 that checks if a lang key exists in a giving language at run time. If the key does not exists, it will add it to the file.

However, if the first time around the key does not exists and I add it, then I do another check "during the same request" to see if the key exists, it will say it does not exist. So the loaded languages will not be aware that I added new keys to the file since Laravel loaded the keys in memory and I am only writing to the file on the hard-disk.

when I evaluate the Illuminate\Translation\Translator class I see that the load method checks if a groups is load it does not load it again.

Here is the Laravel Code

/**
 * Load the specified language group.
 *
 * @param  string  $namespace
 * @param  string  $group
 * @param  string  $locale
 * @return void
 */
public function load($namespace, $group, $locale)
{
    if ($this->isLoaded($namespace, $group, $locale)) {
        return;
    }

    // The loader is responsible for returning the array of language lines for the
    // given namespace, group, and locale. We'll set the lines in this array of
    // lines that have already been loaded so that we can easily access them.
    $lines = $this->loader->load($locale, $group, $namespace);

    $this->loaded[$namespace][$group][$locale] = $lines;
}

Is there a way to force Laravel to read the language each time I request? Or, is there a way to add a key to the currently-in-memory keys? How can I tell laravel that I added new keys?

16th December, 2016

malhayek left a reply on Is There A Way To Get The Column Listing With Column Type Using Eloquent? • 7 months ago

@TerrePorter Schema::getColumnType('posts', 'column') giving me the following error

[Symfony\Component\Debug\Exception\FatalErrorException] Class 'Doctrine\DBAL\Driver\PDOMySql\Driver' not found

@Jaytee I am writing a package that need to get info about the table column. Regardless of that driver that the users is using, I will need that info.

malhayek left a reply on Is There A Way To Get The Column Listing With Column Type Using Eloquent? • 7 months ago

@SaeedPrez describe is a MySQL command. I want to be able to do the same thing for all database drives. SqlServer, SqlLite....

malhayek started a new conversation Is There A Way To Get The Column Listing With Column Type Using Eloquent? • 7 months ago

I am trying to get the column listing along with column type, isNullable, default value.

How can I obtain such info using eloquent?

Is this something possible without having to manually execute a select query againstINFORMATION_SCHEMA.COLUMNS table for every supported database driver?

7th July, 2016

malhayek started a new conversation Is It Possible To Cache Only The Relations In Eloquent? • 1 year ago

I have the following code

SurveyInterview::surveyAndCall($this->interview->surveyId, $this->interview->callId) ->with([ 'current_step.page', 'pages' ]) ->first();

How can I cache only the current_step.page and the pages collections?

I tried something like this

    $myInterview = SurveyInterview::surveyAndCall($this->interview->surveyId, $this->interview->callId)
                              ->with([
                                        'current_step.page' => function($query){ $query->remember(180); },
                                        'pages'
                                    ])
                              ->first();

but this gives me an error

Call to undefined method Illuminate\Database\Query\Builder::remember()

6th July, 2016

malhayek started a new conversation How To Cache Records With Eloquent? • 1 year ago

I am trying to understand how to use cache to cache data when using eloquent to reduce the amount of connections/queries to the database.

It is my understanding, when caching a data set using eloquent you can do the following some

User::Where('status','Active')->with('Teams')->remember(3600)->get();

The above code should cache the result for 3600 seconds "Please correct me if I am wrong."

Now, the second time I run the same line of code, will Eloquent automatically pull the records from the the cache or do I have to do a manual check to see if the records exists in the cache then I load it from the cache otherwise execute the above code?

Also, if I have 10 users on the same system and all 10 need the same result set will the data be reloaded from the cache for 9 users? Or will each dataset be associated with one user?

Finally, can I cache the dataset from a raw query using DB::raw?

Does Eloquent store the query and the dataset in the cache so it knows how to search for it in the cache the next time around?

23rd June, 2016

malhayek left a reply on How To Run Multiple Instances Of Laravel On The Same Domain? • 1 year ago

I actually need it like so

Serv1.example.com:8080/dev Serv1.example.com:8080/staging

Each instance is a folder on serv1.example.com

malhayek started a new conversation How To Run Multiple Instances Of Laravel On The Same Domain? • 1 year ago

I have Apache 2.4 running on Windows Server 2012 with PHP 5.6.23 on port 8080.

Assume that the domain to my server is "serv1.example.com" I need to run 3 Laravel instances production,staging and dev using the following links

serv1.example.com:8080/production
serv1.example.com:8080/staging
serv1.example.com:8080/dev

I found another SO questions which seems to be doing the same thing. But when I tried to do the same thing I get the following error

Forbidden

You don't have permission to access /dev on this server.

Here is what I have done so far. In my httpd-vhosts.conf file I added the following VirtualHost

<VirtualHost *:8080>
    ErrorLog "logs/dev-error.log"
    CustomLog "logs/dev-access.log" common
    DocumentRoot "C:\www\dev\public"
    ServerName serv1.example.com
    ServerAlias /dev
    <Directory "C:\www\dev">
        Options Indexes Includes FollowSymLinks MultiViews
        AllowOverride AuthConfig FileInfo Indexes
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

Then I changed c:\www\dev\public.htaccess the code to the following

<IfModule mod_rewrite.c>
    #Options -MultiViews
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /dev/index.php/?$1 [L]
</IfModule>

What did I do wrong here? how can I access each instance using the same domain?

malhayek left a reply on What Are The Step To Move A Laravel Application Into Production? • 1 year ago

@martinbean Thank you for your input. I have a Windows 2008 R2 Server and I have PHP 5.6.13 running on IIS 7.5. My development environment is basically a different folder on that server. So I have one folder called AppDev "which is where the development environment is running" and "AppProd" which is what is the production environment is running. Since the server is the same, what other steps would I need to do in order to boost performance?

malhayek started a new conversation What Are The Step To Move A Laravel Application Into Production? • 1 year ago

I have an application that I developed using Laravel 5.2. Now I am trying to promote it to production.

What are the best practices to promote the application to production with a solid performance?

Here are the steps that I am thinking that need to take place

  1. Move the new files to the production env.
  2. in the .env file set the following variables APP_ENV=production APP_DEBUG=false CACHE_DRIVER=file SESSION_DRIVER=file QUEUE_DRIVER=sync and of course the database connection :) Do I need to change the cache_driver, session_driver, queue_driver to boot performance? What else should I do/change to get the most speed at my application?

25th February, 2016

malhayek left a reply on How Can I Setup An Laravel Project On IIS 7.5? • 1 year ago

@willvincent ,

I just changed the Physical Path variable from C:\inetpub\wwwroot\laravel to C:\inetpub\wwwroot\laravel\public

Then when I go to http://localhost/laravel I still get 500 Internal Error

malhayek left a reply on IIS7 Laravel 5 • 1 year ago

I followed all the instruction in the answer but getting ERROR 500 when I go to http://localhost/laravel/public/index.php

Here is what I have done so far http://stackoverflow.com/questions/35640159/how-can-i-setup-an-laravel-project-on-iis-7-5

What could I have done incorrectly?

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.