jeudi 1 octobre 2015

Using toastr in a cron job

I'm using laravel toastr feature (link here). I just want to ask if it's possible or is there any way to have the toastr functionality inside a cron job then throw the toastr result in the web page?

Also I dont want to use any web socket. I'm just asking if anyone has a suggestion.

Thanks



via Chebli Mohamed

Laravel 5.1 : FatalErrorException in Encrypter.php line 48: Call to undefined function Illuminate\Encryption\mb_strlen()

I installed laravel 5.1 in my server. I am getting fatal error like in laravel 5.1 Call to undefined function Illuminate\Foundation\Bootstrap\mb_internal_encoding() then i commented the line mb_internal_encoding('UTF-8'); in LoadConfiguration.php..

again i am getting one more fatal error

Laravel 5.1 : FatalErrorException in Encrypter.php line 48: Call to undefined function Illuminate\Encryption\mb_strlen() 

can anybody tell me how to resolve this?



via Chebli Mohamed

Required @SWG\Info() not found

I'm pretty new to using Swagger. Since my project is with Laravel, I use Swaggerevel to document my API. During I tried to generate as follows,

./vendor/bin/swagger app/ -o storage/docs/api-docs.json

It shows that

[INFO] Required @SWG\Info() not found

    get /api/resource.json
-----------------------
1 operations documented
-----------------------
Written to /home/admin/api/gevme-api/storage/docs/api-docs.json

When I tried to access, It localhost:8000/docs, It properly show json api which I generated. But when I tried to access localhost:8000/api-docs, the same error message show again.



via Chebli Mohamed

Laravel 5 how to get many random rows using collections

Based on how get random row laravel-5 I adjusted my query, but still not receiving the expected result.

I have 20 articles in the database and want to get randomly only 3 of them and show them on the page.

My class is just like the following:

public function article()
{
    $article = DashArticle::where('category', '=', 0)->get()->random(3);

    $articleTitle0       = $article[0]->titel;
    $articleAutor0       = $article[0]->autor;
    $articleAbstract0    = $article[0]->abstract;
    $articleSource0      = $article[0]->source;
    $articleTitle1       = $article[1]->titel;
    $articleAutor1       = $article[1]->autor;
    $articleAbstract1    = $article[1]->abstract;
    $articleSource1      = $article[1]->source;
    $articleTitle2       = $article[2]->titel;
    $articleAutor2       = $article[2]->autor;
    $articleAbstract2    = $article[2]->abstract;
    $articleSource2      = $article[2]->source;

    return compact(
        'articleTitle0', 'articleAutor0', 'articleAbstract0', 'articleSource0',
        'articleTitle1', 'articleAutor1', 'articleAbstract1', 'articleSource1',
        'articleTitle2', 'articleAutor2', 'articleAbstract2', 'articleSource2'
    );
}

And here part of the view:

<div id="a-slide" class="carousel slide auto panel-body">
    <ol class="carousel-indicators out">
        <li class="active" data-slide-to="0" data-target="#a-slide"></li>
        <li class="" data-slide-to="1" data-target="#a-slide"></li>
        <li class="" data-slide-to="2" data-target="#a-slide"></li>
    </ol>
    <div class="carousel-inner">
        <div class="item active" style="padding: 0 16px;">
            <p style="font-size: 16px; font-weight: bold;">{!! $articleTitle0 !!}</p>
            <p class="text-muted">{!! $articleAutor0 !!}</p>
            <p><strong>Abstract:</strong><br />{!! $articleAbstract0 !!}</p>
            <p>
                <a href="$articleSource !!}" target="_blank">
                    {!! $articleSource0 !!}
                </a>
            </p>
        </div>

        <div class="item" style="padding: 0 16px;">
            <p style="font-size: 16px; font-weight: bold;">{!! $articleTitle1 !!}</p>
            <p class="text-muted">{!! $articleAutor1 !!}</p>
            <p><strong>Abstract:</strong><br />{!! $articleAbstract1 !!}</p>
            <p>
                <a href="{!! $articleSource1 !!}" target="_blank">
                    {!! $articleSource1 !!}
                </a>
            </p>
        </div>

The problem is when I let the random = 3 ($article = DashArticle::where('category', '=', 0)->get()->random(3); I get following error: "Undefined offset: 1"

and when I user random = 20 (the total number of rows in the table) it works but I don't become any random articles but always the first 3 lines of the table.

I would appreciate any help! Thanks!



via Chebli Mohamed

Session return not valid information from Laravel 5.1 Dingo API

I am making an website with client (make by laravel 5.1) interacting with an API (make by Dingo and Laravel 5.1 too). But i can't get the return value from session. I was tried everything i can but nothing good!, please you guys help me. I will very appreciated if anyone direct me to the way to solve this problem, this is my code i use to test the returned session.

public function test(Request $request, $ucode){
    $sessionToke =  $request->session()->all();

    return  $sessionToke; }

This is the code in client side which i use to get session value:

 public function checkState(Request $request, $ucode){
    $params = ''.$ucode;
    $action = 'test';
    $result = ApiController::getAPI($params, $action);
    return json_encode($result);
}

And the problem is when i try to get value directly from the api (in postman) everything is good but nothing show up when i try to call through the client side routes (even in ajax and postman). This is the screen capture: enter image description here enter image description here

Thank you!



via Chebli Mohamed

Laravel 5.1 : syntax error, unexpected 'class' (T_CLASS), expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' [duplicate]

I just uploaded my laravel to server as soon as i enter into the site i am getting pasrse error like syntax error, unexpected 'class' (T_CLASS), expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$'
My code is as follows:

$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);

$response = $kernel->handle(
    $request = Illuminate\Http\Request::capture()
);

$response->send();

$kernel->terminate($request, $response);

can any one tell me why it is throwing error?



via Chebli Mohamed

Laravel 5 model relationship many to many

I have the following table setup:

countries (id)

languages (id)

country_languages (id, country_id, language_id)

In plain SQL I can fetch all countries with their corresponding language(s) fairly easily:

SELECT * FROM countries

INNER JOIN country_languages
    ON country_languages.country_id = countries.id

INNER JOIN languages
    ON languages.id = country_languages.language_id;

In Laravel (5), using the following works:

In Country model:

public function countryLanguages()
{
    return $this->hasMany('CountryLanguage');
}

In CountryLanguage Model:

public function language()
{
    return $this->belongsTo('Language');
}

$countries = Country::with('countryLanguages.language');

I'd like have a single relationship method languages however that can be called directly on the Country model. Is this possible? I've tried the hasManyThrough and other methods but so far no luck!



via Chebli Mohamed