jeudi 1 septembre 2016

Laravel 5. Retrieve data from DB::select

Code:

        $best_price = DB::select('Some SQL statement');

        foreach($best_price as $best_price_id) {
            $best_price_id->id;
        };


        $product->best_price_id = $best_price_id;

        return $product->best_price_id;

Result:

The Response content must be a string or object implementing __toString(), "object" given.

Definately I am retrieving information from the DB incorrectly. Please suggest better option.



via Chebli Mohamed

Laravel 5.1: Null field being converted to blank in the function create

The Model.php has the following function:

public static function create(array $attributes = []) { $model = new static($attributes); $model->save(); return $model; }

The attributes parameter has null value for each field when they are not filled by the user. However, after call new static($attributes) one field is converted to "". I do not understand. Even when all fields are null, only one field is converted to "" (blank).

I do not want this convertion to blank. Anyone knows what is happening in this case?

Thanks. Best regards.



via Chebli Mohamed

Laravel 5.1 - Make a string with variables

i have this code in my index of products of my ecommerce.

<img src="" title="" alt="">

It create a link like this:

http://localhost:8000/shop/t-shirt/men/some-slug-product

i would like create like this:

http://localhost:8000/shop/t-shirt,men,some-slug-product

So i can create image and save the title image with variables separated by comma.

I tryed different option but it doesn't work well.

Thank you for your help! :)



via Chebli Mohamed

Best way to to test and implement security on my website

How should i test my website security in laravel 5(/overall) and if its week what should i do to improve it?

I have no experience when it comes to security testing/check.

Please help, much appreciated.



via Chebli Mohamed

Laravel if statement with other variable value

I try to get data from a model, but the value of the column name from the data model is in another variable. Here's a little preview what I try to achieve:

switch($device->target_objectclass_id) {
    case 10:
        $handler = Servers::findOrFail($device->target_object_id);
    default:
        break;
}

if($handler->($condition->column) ($condition->condition) ($condition->value)) {
    //process the other data it it's true
}

Example of what should be displayed:

if($handler->status == 1) { 
    //handle data 
}

The reason behide this is a little bit complicated. The user's need to create triggers which will be executed.


For example:

  • check table where column condition value
  • check servers where status == 1

Hope someone has an answer if you can understand my problem...



via Chebli Mohamed

Make website load images faster

What is the best way to load my images faster on my website using the laravel 5 framework? I can't seem to find a clear answer for this problem?



via Chebli Mohamed

Session is not being saved in laravel 5.1

I am new in laravel. I am trying to save a session on page load. After page load when I am echoing the session it is coming properly. But when I am trying to fetch it in different page it is not coming.

I am using file driver.

Added this line on the top of the controller use Illuminate\Support\Facades\Session;

Like this I am saving the sesion

if (Session::has('ss')) { //check session start
        } else { Session::put('ss', $ss); Session::save(); }

If I do echo Session::get('ss') after the above line it is working fine. But if I do echo Session::get('ss') in another function or controller it is not coming.

NB : The problem is happening only on server. Local it is fine. I am using godaddy. I gave 777 permission to the session storage folder and subfolders but still no luck. My whole project got stuck only for this problem.

If I have to use memcache please guide me how to save session in that. I changed the driver file to memcache in the config/session.php . Rest I kept same like

if (Session::has('ss')) { //check session start
            } else { Session::put('ss', $ss); Session::save(); }

Still it is not working. Please help me on this.



via Chebli Mohamed