vendredi 29 mars 2019

Laravel - Return the manipulated value from a collection

I would like to manipulate a value from a collection! I receive the stylenumber as 12345-D-002. I have to explode this on "-" to have the first part of the stylenumber.

Collection-Code from Model Order:

public static function getPicklistToday($date)
    {
        $sql = "
            SELECT
                oxid_orderarticles.OXARTNUM as style,
                sum(oxid_orderarticles.OXAMOUNT) as ANZAHL,
                oxid_orderarticles.OXSELVARIANT,
                oxid_import.imported
            FROM oxid_orderarticles
            LEFT JOIN oxid_import
                ON oxid_import.oxid = oxid_orderarticles.OXORDERID
                WHERE DATE(oxid_import.imported) = :date
            GROUP BY oxid_orderarticles.OXARTNUM
            ORDER BY oxid_orderarticles.OXARTNUM ASC
        ";
        $pick = DB::select($sql,[':date'=>$date]);

        return $pick;
    }

This is the method, which should explode the returned 'style' from the query, also in Model Order:

    public function getParentStyle()
    {

        $parent = explode("-",$this->style);

        return $parent[0];
    }

Method in the OrderController:

    //------------------------
    public function today()
    {
        $today = Order::getPicklistToday(Carbon::now()->format('Y-m-d'));

        return view('order.today',compact('today'));

    }

Part of the view today.blade.php:

    @foreach($today as $pos)
    <tr>
      <td><i class="far fa-square"></i></td>
      <td><b>x</b></td>
      <td></td>
      <td></td>
      <td></td>
    </tr>
    @endforeach

I receive the following error message:
Call to undefined method stdClass::getParentStyle() (View: /var/www/html/app/resources/views/order/today.blade.php)

How should the method getParentStyle() look like to get my code running?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2V1NktH
via IFTTT

Using pivot column data in a policy

I have an organization model ,broadcast model and a broadcast_organization pivot with an extra organization_specific column.I want to apply a policy for updating a broadcast only if organization_specific is true, so far none of the ways ive tried have worked.

Models

public function organizations()
{
    return $this->belongsToMany('App\Models\Organization')
    ->withPivot(['organization_specific']);
}


public function broadcasts()
{
    return $this->belongsToMany('App\Models\Broadcast')
    ->withPivot(['organization_specific']);
}

Broadcast Update Policy

 public function update(User $user, Broadcast $broadcast)
{

    if($this->isAdmin($user)){
        foreach($broadcast as $broadcasts) {
            if($broadcasts->pivot->organization_specific === 'true') {
                return true;
            }
        }
    }
    return false;
}



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2K2BaA3
via IFTTT

Laravel 5.1 How to Log - PHP Fatal error: Allowed memory size of X bytes exhausted

I am having this random out of memory issue in my production for specific api's calls. Laravel log has nothing logged. I am not able to figure out for what parameters it is going out of memory.

Is there a way to setup register_shutdown_function and put it in Laravel somewhere, where in I can put the stack trace in the log. Or any other way to log the error and stack trace for the same?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2V2cZmh
via IFTTT

How to generate qrcode with data from mysql

Please help me how to generate qrcode with data from mysql.

This is my controller

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class QrController extends Controller
{

   public function make()
    {
        $pelajar_id = md5(time(). mt_rand(1,100000));

        $user = ('qr'.'/'.$pelajar_id.'.png');
        \QRCode::text($pelajar_id)->setOutFile($user)->png();
    }

}

This is my web.php

//qrcode
Route::get('/qrcode', 'QrController@make');

i just declare $pelajar_id to random variables because i dont know how to retrieve data from mysql. Please help me....



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2OyDTzq
via IFTTT

In envoy error referring db at composer installing step

In laravel 5.8 I run envoy command and it is supposed that new release is uploaded to new subdirecory and after the project is cloned and composer installed .env file would be copied to the project. But running command I got error referring db, as .env is not found:

$ envoy run VotesDeploy
lardeployer@NNN.NN.NNN.N's password: 
[lardeployer@NNN.NN.NNN.N]: $release_number :: /var/www/html/VotesDeployed/release/20190329095641
[lardeployer@NNN.NN.NNN.N]: $database_factories_path :: /var/www/html/VotesDeployed/release/20190329095641/database/factories
[lardeployer@NNN.NN.NNN.N]: $git_clone_command git clone --depth 1 -b master "git@bitbucket.org:myaccount/votes.git"  "/var/www/html/VotesDeployed/release/20190329095641"::
[lardeployer@NNN.NN.NNN.N]: Cloning into '/var/www/html/VotesDeployed/release/20190329095641'...
[lardeployer@NNN.NN.NNN.N]: Checking out files:  13% (198/1468)
...
[lardeployer@NNN.NN.NNN.N]: Checking out files: 100% (1468/1468)
[lardeployer@NNN.NN.NNN.N]: Checking out files: 100% (1468/1468), done.
[lardeployer@NNN.NN.NNN.N]: Step # 1 : Repository has been cloned
lardeployer@NNN.NN.NNN.N's password: 
[lardeployer@NNN.NN.NNN.N]: Step # 2 start : composer_installing dependencies installing
[lardeployer@NNN.NN.NNN.N]: Loading composer repositories with package information
[lardeployer@NNN.NN.NNN.N]: Updating dependencies
[lardeployer@NNN.NN.NNN.N]: Package operations: 124 installs, 0 updates, 0 removals
...
[lardeployer@NNN.NN.NNN.N]: Loading from cache
[lardeployer@NNN.NN.NNN.N]: - Installing ratchet/rfc6455 (0.2.4):
[lardeployer@NNN.NN.NNN.N]: Loading from cache
[lardeployer@NNN.NN.NNN.N]: - Installing cboden/ratchet (v0.4.1):
[lardeployer@NNN.NN.NNN.N]: Loading from cache
[lardeployer@NNN.NN.NNN.N]: - Installing beyondcode/laravel-websockets (1.1.1):
[lardeployer@NNN.NN.NNN.N]: Loading from cache
[lardeployer@NNN.NN.NNN.N]: Writing lock file
[lardeployer@NNN.NN.NNN.N]: Generating optimized autoload files
[lardeployer@NNN.NN.NNN.N]: > Illuminate\Foundation\ComposerScripts::postAutoloadDump
[lardeployer@NNN.NN.NNN.N]: > @php artisan package:discover
[lardeployer@NNN.NN.NNN.N]: In Connection.php line 664:
[lardeployer@NNN.NN.NNN.N]: SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using pa
[lardeployer@NNN.NN.NNN.N]: ssword: NO) (SQL: select * from information_schema.tables where table_schem
[lardeployer@NNN.NN.NNN.N]: a = forge and table_name = vt2_settings)
[lardeployer@NNN.NN.NNN.N]: In PDOConnection.php line 31:
[lardeployer@NNN.NN.NNN.N]: SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using pa
[lardeployer@NNN.NN.NNN.N]: ssword: NO)
[lardeployer@NNN.NN.NNN.N]: In PDOConnection.php line 27:
[lardeployer@NNN.NN.NNN.N]: SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using pa
[lardeployer@NNN.NN.NNN.N]: ssword: NO)
[lardeployer@NNN.NN.NNN.N]: Script @php artisan package:discover handling the post-autoload-dump event returned with error code 1
[✗] This task did not complete successfully on one of your servers.

My /_wwwroot/lar/DeploymentApps/votes/Envoy.blade.php:

@setup
    // Under directory /mnt/_work_sdb8/wwwroot/lar/DeploymentApps/votes RUN
    // export PATH="$PATH:~/.composer/vendor/bin"
    // envoy run VotesDeploy
    $server_login_user= 'lardeployer';

    $timezone= 'Europe/Kiev';

    $path= '/var/www/html/VotesDeployed';

    $current = $path . '/current';

    // git clone git@bitbucket.org:myaccount/votes.git
    $repo= 'git@bitbucket.org:myaccount/votes.git';

    $branch= 'master';

   // Directory and files with chmod 755
    $writableDirs= [
        '/storage/logs',
        '/bootstrap/cache'
    ];
    $now_date = new DateTime('now', new DateTimeZone($timezone));

    $release_number = $path . '/release/' . $now_date->format('YmdHis');

    $git_clone_command = 'git clone --depth 1 -b '.$branch.' "'.$repo.'" '.' "'.$release_number.'"';

    $database_factories_path= $release_number.'/database/factories';

@endsetup

@servers(['production' => $server_login_user.'@NNN.NN.NNN.N'])


@task( 'clone_project', ['on'=>$on] )

    echo '$release_number :: ';

    echo '$database_factories_path :: ';

    echo '$git_clone_command ::';


    mkdir -p 


    

    mkdir -p 

    echo "Step # 1 : Repository has been cloned";
@endtask


@task( 'composer_installing', ['on'=>$on] )
    cd 

    echo "Step # 2 start : composer_installing dependencies installing";
    composer install --no-interaction --no-dev --prefer-dist

    echo "Step # 2 : composer_installing dependencies has been installed";
@endtask


@task( 'artisan_running', ['on'=>$on] )
    cd 

    ln -nfs /.env .env
    chgrp -h www.data .env

    php artisan config:clear

    php artisan migrate

    php artisan clear-compiled -- env=production

    php artisan optimize --env=production

    echo "Step # 3 : Production dependencies has been installed";
@endtask


@task( 'chmod_settings', ['on'=>$on] )
    chgrp -R www-data 
    chmod -R ug-rwx 

    echo "Step # 4 : chmod_settings = Permissions setting";
    @foreach($writableDirs as $file)
        chmod -R 775 /

        chown -R :www-data /

        echo "Permisions has been for file ";
    @endforeach
    echo "Step # 4 : chmod_settings = Permissions has been set";
@endtask



@task( 'update_symlinks' )
    ln -nfs  ;

    chgrp -h www-data ;
    echo "Step # 5 : Symlink has been set";
@endtask


@macro('VotesDeploy',['on'=>'production'])
    clone_project
    composer_installing
    artisan_running
    chmod_settings
    update_symlinks
@endmacro

Why there is refering to db at composer_installing stage. Error message is :

select * from information_schema.tables where table_schema = forge and table_name = vt2_settings

vt2_settings is my table, but I use it in my controls only. Why it is referred by Illuminate\Foundation\ComposerScripts::postAutoloadDump as I see in error description ?

Any ideas how to fix it?

Thanks!



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2Yvlvw6
via IFTTT

Laravel Backpack How to create new page without CRUD

Sorry Guy I'm new with Laravel Backpack 4.3 need your expertise.

I wanna create a simple page without CRUD is that possible on Laravel Backpack, if yes Which file I need to work on?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2CLlScO
via IFTTT

jeudi 28 mars 2019

"The POST method is not supported for this route. Supported methods: GET, HEAD

I am trying to get the token from stripe by submitting the stripe form.It gives me the error
"The POST method is not supported for this route. Supported methods: GET, HEAD.

I already have tried with

@method('GET') gives back the same page
@method('HEAD') gives back an empty page

Here is my stripe form:

<form action="" method="POST">
    @csrf
      <script
        src="https://checkout.stripe.com/checkout.js" class="stripe-button"
        data-key="pk_test_tjs3R2OtR8kbuis8IPNlOJAh008bBqanO5"
        data-amount=
        data-name="Online Payment"
        data-description="E Commerce Website"
        data-image="https://stripe.com/img/documentation/checkout/marketplace.png"
        data-locale="auto"
        data-zip-code="true">
      </script>
</form>


My Route:

Route::post('/bill/payment',[
'uses'=>'PaymentController@pay',
'as'=>'bill.payment'
]); 



And my Controller:

 public function pay()
    {
        dd(request()->all());
    }

I expect the form data to die dump in my Controller.Any Help will be much appreciated.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2UYrXcO
via IFTTT