jeudi 14 juin 2018

Getting variables declared in a template in laravel

I have dynamically created view in laravel which contains a set of variables.Before rendering the view I need to pass these variables by

$content = view(['template' => html_entity_decode($content)], $values)->render();

$content is the html template with variables.Eg: '<div><strong>Location: </strong>{!!$item->get("location")->{0}->{"title"}!!}<br />'.$values is the object array with values.Sometimes the values passed to the template does not contains the variables available in template.This causes the error'Trying to get non property on a object'.Is there any solution to get all variables inside the template before rendering in laravel.I tried with preg_match,but it makes the execution slower.



via Chebli Mohamed

samedi 9 juin 2018

Convert array laravel

I use Laravel framework and I have an array:

[▼
  "0.022" => "24.00000000"
  "0.013" => "506.00000000"
  "0.041" => "65.00000000"
]

Could you help me to convert it to new format like this:

[▼
  0 => {▼
    "xxx": 0.022
    "yyy": 24.00000000
  }
  1 => {▼
    "xxx": 0.013
    "yyy": 506.00000000
  }
  2 => {▼
    "xxx": 0.041
    "yyy": 65.00000000
  }
]

Thank you very much.



via Chebli Mohamed

jeudi 7 juin 2018

Laravel $schedule->call() ReflectionException: Class does not exist

I am try to test $schedule->call method (Kernel.php) using this command.

php artisan schedule:run

Then it's gives me this error:

  [ReflectionException]                                       
  Class App\Http\Controllers\DeactiveELV does not exist

source code:

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use Illuminate\Support\Facades\Log;
class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        \Log::info('Just for testing...');
         $schedule->call('App\Http\Controllers\DeactiveELV@shutdown')->everyMinute();
    }
}



via Chebli Mohamed

mercredi 6 juin 2018

Laravel Logout a specific user

I know it is an old topic, and I know thousands similar questions exist(if not millions), but no one gives a specific answer to my question.

I have a ban feature in my system, where the master(or admin) of the app can ban unwanted users, but if the last have already open session, they still able to use the website without any problem(until they log out, then they can't log in again).

Currently, I moved to redis, and I arranged everything, but my problem still with users who are logged in before I implement a new solution, as in my system I have a kind of monitoring and I can see that they spend money and enjoy the website without any problem(ecommerce web app).

I won't add a check or middleware on every request, because that will just slow down the app.
Also, some solutions discussing about looking in session file from laravel, will not help in my case.
Any suggestion or solution?



via Chebli Mohamed

Does laravel 5.6 support https://ift.tt/2LmpHqs this package?

While installing the above package I'm getting error as below:

Your requirements could not be resolved to an installable set of packages.

Problem 1
- don't install laravel/framework 5.6.x-dev|don't install illuminate/support 4.2.x-dev
- don't install laravel/framework v5.6.0|don't install illuminate/support 4.2.x-dev
- don't install laravel/framework v5.6.1|don't install illuminate/support 4.2.x-dev
- don't install laravel/framework v5.6.10|don't install illuminate/support 4.2.x-dev
- don't install laravel/framework v5.6.11|don't install illuminate/support 4.2.x-dev
- don't install laravel/framework v5.6.12|don't install illuminate/support 4.2.x-dev
- don't install laravel/framework v5.6.13|don't install illuminate/support 4.2.x-dev
- don't install laravel/framework v5.6.14|don't install illuminate/support 4.2.x-dev
- don't install laravel/framework v5.6.15|don't install illuminate/support 4.2.x-dev
- don't install laravel/framework v5.6.16|don't install illuminate/support 4.2.x-dev
- don't install laravel/framework v5.6.17|don't install illuminate/support 4.2.x-dev
- don't install laravel/framework v5.6.18|don't install illuminate/support 4.2.x-dev
- don't install laravel/framework v5.6.19|don't install illuminate/support 4.2.x-dev
- don't install laravel/framework v5.6.2|don't install illuminate/support 4.2.x-dev
- don't install laravel/framework v5.6.20|don't install illuminate/support 4.2.x-dev
- don't install laravel/framework v5.6.21|don't install illuminate/support 4.2.x-dev
- don't install laravel/framework v5.6.22|don't install illuminate/support 4.2.x-dev
- don't install laravel/framework v5.6.23|don't install illuminate/support 4.2.x-dev
- don't install laravel/framework v5.6.24|don't install illuminate/support 4.2.x-dev
- don't install laravel/framework v5.6.3|don't install illuminate/support 4.2.x-dev
- don't install laravel/framework v5.6.4|don't install illuminate/support 4.2.x-dev
- don't install laravel/framework v5.6.5|don't install illuminate/support 4.2.x-dev
- don't install laravel/framework v5.6.6|don't install illuminate/support 4.2.x-dev
- don't install laravel/framework v5.6.7|don't install illuminate/support 4.2.x-dev
- don't install laravel/framework v5.6.8|don't install illuminate/support 4.2.x-dev
- don't install laravel/framework v5.6.9|don't install illuminate/support 4.2.x-dev
- don't install illuminate/support 4.2.x-dev|remove laravel/framework v5.6.23
- gufy/reseller-club v1.0.0 requires illuminate/support 4.2.* -> satisfiable by illuminate/support[4.2.x-dev].
- Installation request for gufy/reseller-club ~1 -> satisfiable by gufy/reseller-club[v1.0.0].
- Installation request for laravel/framework 5.6.* -> satisfiable by laravel/framework[5.6.x-dev, v5.6.0, v5.6.1, v5.6.10, v5.6.11, v5.6.12, v5.6.13, v5.6.14, v5.6.15, v5.6.16, v5.6.17, v5.6.18, v5.6.19, v5.6.2, v5.6.20, v5.6.21, v5.6.22, v5.6.23, v5.6.24, v5.6.3, v5.6.4, v5.6.5, v5.6.6, v5.6.7, v5.6.8, v5.6.9].

suggest me whether this package will be supported in laravel 5.6 or not...



via Chebli Mohamed

mardi 5 juin 2018

How to obtain the route path of a file that was accessed by FTP?

I'm trying to get the route where I have several stored files which I get through an FTP connection from the Laravel 5.1 Filesystem, this is then copied to my server

$origen = Storage::disk('ftp')->get($file)->getRealPath();
$destino = 'ruta de mi servidor';

Storage::copy($origen, $destino);

But the origin line always leaves error Call to a member function getRealPath() on string. I have also tried Storage::disk('ftp')->getDriver()->getAdapter()->getPathPrefix();, but in this I can not answer, nothing returns, or Storage::disk('ftp')->url($file) and I also get an error that it is not a function.

Any solution to obtain this route?. Sorry for the bad English



via Chebli Mohamed

samedi 2 juin 2018

Java Script getJSON properly not working in laravel 5.+?

Controller

public function getback(Request $request)
{


    $chart = DB::table('BirthChart_1')
             ->where('FileId', 123)
             ->get();



            foreach ($chart as $key ) {
                $f[] = [$key->k1,$key->k2,$key->k3,$key->k4,$key->k5,$key->k6,$key->k7,$key->k8,$key->k9,$key->k10];

            }

            return response()->json($f);
}

javascript

$(document).ready(function() {
  $.getJSON("/getback", function(data) {
    var items = [];

    $.each(data, function(key, val) {
      items.push(val);
    });
    alert(items);
    alert(items[0]);
    alert(items[1]);

  });
});

http://127.0.0.1:8000/getback Result... [[3,4,null,null,null,5,null,null,null,null]]

http://127.0.0.1:8000 Result

alert(items); // 3,4,,,,5,,,,
alert(items[0]); // 3,4,,,,5,,,,  (here I want 3)
alert(items[1]); // undefined (here ,I want 4)

What is my mistake in here ? or how to correct it properly ?



via Chebli Mohamed