samedi 30 juin 2018

How to use a variable in blade array

How can i use a variable inside a blade array like so

$my_var = 54

array('class'=>'info', 'link'=> '', 'message'=> 'AllRenewals', 'icon'=> 'history')

Laravel seems to not be able to understand its a vairable



via Chebli Mohamed

vendredi 29 juin 2018

Is it better to post json data or just key-value pairs in Laravel Apis?

i have developed the Api in Laravel now one of my team member saying that i will post the data in Json format during api call. now what should i do?

is it better to post data in Json format or just use key-value pairs? please help



via Chebli Mohamed

jeudi 28 juin 2018

Laravel: echo javascript function if a certain session variable is present

Is it possible to do something like this ...

@if(Session::has('foo'))
    <script>
    // My JavaScript function
    </script>
@endif

I am trying to put Facebook pixel code only if a certain session variable is there.

Please advise.



via Chebli Mohamed

lundi 25 juin 2018

Error on trying to apply a subscription to the newly created custome

On the Backend, we are using Laravel 5.1 because the previous developer decided to use this artifact instead of 5.4, which was available at the time of the project creation. To perform the payments, subscriptions, invoices - we are using Billable(Cashier) with Stripe.

The problem is next one, that we are facing this issue only on the Staging (dev) server, but not on the Local environment:

Laravel's Stripe issue on the try to apply the subscription plan to the customer

This is how it was done (sorry for not following PSR. We have no time to refactor, as the client is burning)

    public function postJoin(Request $request)
    {
        $input = $request->all();

        try {
            $this->user->subscription($input['plan'])
                ->create($this->user->setOrGetStripeCustomerId(), [
                    'email' => $this->user->email
                ]);

            $this->user->update(['paid' => true]);

            return redirect('subusers')
                ->with('info', Lang::get('app.membership_active'));

        } catch (Exception $e) {
            return back()->with('info', $e->getMessage());
        }
    }

What can cause this issue?



via Chebli Mohamed

dimanche 24 juin 2018

Laravel required if validation issue

Laravel required if validation issue

Blade:

           
        <div class="form-group row">
            
            <div class="col-md-9">
                
            </div>
        </div>
        <div class="form-group row">
            <label class="col-md-3 col-form-label font-weight-bold">Mandrill</label>
        </div>
        <div class="form-group row">
            
            <div class="col-md-9">
                
            </div>
        </div>
        <div class="form-group row">
            <div class="col-md-9 ml-md-auto">
                
                 <a class="btn btn-danger" href=""><i class="far fa-times-circle"></i> Cancel</a>
            </div>
        </div>
    

Form Request:

    return [
        'driver' => 'required',
        'mailgun.*.domain' => 'required_if:driver,mailgun'
    ];

Validation always fails. Please suggest me if i miss anything.



via Chebli Mohamed

samedi 23 juin 2018

Unable to delete a record when created foreign-key constraints manually in mysql without using migration.

I have created database tables manually and i have also created foreign key constraints in tables manually without using migration. now when i am going to delete a record it giving me following error-

Integrity constraint violation: Cannot delete or update a parent row: a foreign key constraint fails

Note: i can't use migration because database was already created.



via Chebli Mohamed

vendredi 22 juin 2018

error while installing composer and open project

Error when i use this command composer install ,

Fatal error: composerRequire1ee160e16912ab41755f87617b1e4590(): Failed opening required 'C:\xampp\htdocs\try\ytl\vendor\composer/../psy/psysh/src/functions.php' (include_path='C:\xam pp\php\PEAR') in C:\xampp\htdocs\try\ytl\vendor\composer\autoload_real.php on line 66

when i open project in browser : error

Warning: require(C:\xampp\htdocs\try\ytl\vendor\composer/../psy/psysh/src/functions.php): failed to open stream: No such file or directory in C:\xampp\htdocs\try\ytl\vendor\composer\autoload_real.php on line 66

Fatal error: require(): Failed opening required 'C:\xampp\htdocs\try\ytl\vendor\composer/../psy/psysh/src/functions.php' (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\try\ytl\vendor\composer\autoload_real.php on line 66

tired with below command:

composer dump-autoload

below code in vendor/autoload.php:

<?php

// autoload.php @generated by Composer

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInit1ee160e16912ab41755f87617b1e4590::getLoader();



via Chebli Mohamed

jeudi 21 juin 2018

Laravel API login with username and token

I am developing a laravel API(MyAPI) with the 5.1 version.I am connecting to this API from a widget which hosted in another website.it has a separate API(hostAPI). I need to authenticate user when widget loaded.

following are my requirement.

" When the widget loads it will attempt to authenticate. It will send a request to the MyAPI with

{
 username: username,
 token: token
}

MyAPI will POST this information on to the hostAPI. This will return either success or a 401.

On sucess, we log the user in. We may need to create an account if an user with that name does not exist"

how can i auth a user with only username and a token key enter image description here



via Chebli Mohamed

lundi 18 juin 2018

Getting registration error messages on custom register page Laravel

I've worded my question really bad but I've been looking through Laravel files and docs for hours and have no solutions.

I have a custom php page that has a register form:

customRegister.php:

<?php require_once __DIR__ . '/../../../vanguard/extra/auth.php';\
$foundUsername = "testUser";
?>

<form role="form" action="https://my.neonn.com.au/register" method="POST" id="registration-form" autocomplete="off">
    <input type="hidden" value="<?= csrf_token() ?>" name="_token">
    <input type="hidden" name="username" id="username" value="<?php echo $foundUsername; ?>">
    <input type="password" class="form-control empty" id="inputPassword" name="password">
    <input type="password" class="form-control empty" id="inputPasswordCheck" name="password_confirmation">

    <button type="submit">Submit</button>
</form>

I am attempting to display the "partial/messages" errors that are displayed when the password does not meet the rules. e.g contains 6 characters.

I have tried things like adding this to my code <?= @include('partials/messages') ?>. nothing seems to work.



via Chebli Mohamed

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