mercredi 2 janvier 2019

Laravel Select DB raw sum with where clause not work

I am trying to retrieve my result and every day every service have how much total charged, total refund. My logic not work properly cause of where condition.I cant understand.

My code

    $transactions = Transaction::with('service')
        ->select('id','transaction_no','created_at','service_id')
        ->selectRaw(DB::raw('sum(deducted) as success where refund = 0'))
        ->addSelect(DB::raw('sum(charges) as charges'))
        ->addSelect(DB::raw('sum(deducted) as refunded where refund != 0'));
    $transactions = $transactions->groupBy('service_id',DB::raw('DATE(created_at)'))->get();
    return $transactions->toJson(JSON_PRETTY_PRINT);

I think issue is where refund != 0' and where refund = 0'



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2BTqJHG
via IFTTT

Laravel many to many with input pivot table

This is a system for borrowing laboratory equipment, where users are required to fill in their personal data first before being able to borrow laboratory equipment. There is a tool lending form consisting of, name and address that will be stored in the "loan_equipment" table, selecting a list of tools taken from the "lab_equipment" table, and the data will be stored in the "loan_lists" table with the many to many method.

I have 3 tables loan_equipment table (id, name, address), lab_equipment table (id, name), loan_lists table (loan_equipment_id, lab_equipment_id, amount)

This is the LoanEquipment.php model:

public function labEquipment()
{
    return $this->belongsToMany('App\LabEquipment', 'loan_lists', 'loan_equipment_id',
    'lab_equipment_id')->withTimestamps();
}

This is the LabEquipment.php model:

public function loanEquipment()
{
    return $this->hasMany('App\LoanEquipment');
}

This is the LoanEquipmentController.php controller:

public function store(Request $request)
{
    $this->validate($request, [
        'name' => 'required|max:128',
        'address' => 'required',
        'labEquipment' => 'required'
    ]);

    $input = LoanEquipment::create($request->all());
    $input->labEquipment()->attach($request->input('labEquipment'));

    Session::flash("flash_notification", [
        "level" => "success",
        "message" => "Success $input->name."
    ]);

    return redirect()->route('loan.index');
}

This is a view or form to fill in the loan list tool form.blade.php:

Input Name:

<div class="form-group ">
{!! Form::label('name', 'Nama', ['class' => 'col-md-2 control-label']) !!}
<div class="col-md-6">
    {!! Form::text('name', null, ['class' => 'form-control']) !!}
    <strong>{!! $errors->first('name', '<p class="help-block">:message</p>') !!}</strong>
</div>

Input Address:

<div class="form-group ">
{!! Form::label('address', 'Address', ['class' => 'col-md-2 control-label']) !!}
<div class="col-md-6">
    {!! Form::text('address', null, ['class' => 'form-control']) !!}
    <strong>{!! $errors->first('address', '<p class="help-block">:message</p>') !!}</strong>
</div>

Selected and Input labEquipment and amount

<div class="form-group ">
{!! Form::label('labEquipment', 'Daftar Alat Laboratorium', ['class' => 'col-md-2 control-label']) !!}
<div class="col-md-6">
    @if(count($listsLabEquipment) > 0)
        @foreach($listsLabEquipment as $key => $value)
            <div class="checkbox">
                <label for="">{!! Form::checkbox('labEquipment[]', $key, null) !!}
                    
                </label>
            </div>
            {!! Form::text('amount', null, ['class' => 'form-control']) !!}
        @endforeach
    @endif
    <strong>{!! $errors->first('labEquipment', '<p class="help-block">:message</p>') !!}</strong>
</div>

How can I add or enter data on the number of borrowed tools through the tool lending form? And stored in the "loan_lists" table with the name "amount". How should the code I make in the controller, model, and view?

Thank you for your help



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2TnH2n4
via IFTTT

How do I print Data from table

1) This is my order table :

Schema::create('orders', function (Blueprint $table) {
        $table->increments('id');
        $table->integer('user_id')->unsigned();
        $table->integer('category_id')->unsigned();
        $table->integer('product_id')->unsigned();
        $table->integer('variant_id')->unsigned();
        $table->integer('quantity');
        $table->integer('total');
        $table->timestamps();
        $table->foreign('user_id')->references('id')->on('users');
        $table->foreign('category_id')->references('id')->on('categories');
        $table->foreign('product_id')->references('id')->on('products');
        $table->foreign('variant_id')->references('id')->on('variants');
    });

2) This is my Order Blade :

<tbody>

        @foreach($orders as $order)
        <tr>
        <td></td>
        <td></td>
        <td>/-</td>
        </tr>
        @endforeach 
    </tbody>

3) This is my OrderController :

public function index()
{
    $orders = Order::where('user_id', auth()->user()->id)->get();
    return view('orders', compact('orders', 'variants'));
}

Now I want to print the variant name in my blade file but only thing I can print is id's. I've tried many things but still can't get the precise answer. I know it can be done with foreign keys but how do I use these foreign keys to print variant_name or anything from variant table.



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2GQJ1Pq
via IFTTT

mardi 1 janvier 2019

laravel ajax is not working , it seen fail


i want to insert data from register form by ajax.
but I see ajax failed in my console log.
I can't understand what is problem ?
here is my js :

$('#Personal_Information').on('submit', function(event){
        event.preventDefault();
        var form_data = $(this).serialize();
        $.ajax
        ({
            type: "POST",
            dataType : 'json',
            url: "", 
            data: {csrf_token:"", data: form_data}
        }).done( function(data){
            console.log('Ajax was Successful!')
            console.log(data)
        }).fail(function(){
            console.log('Ajax Failed')
        });

here is my route :

Route::get('/update-profile', 'personalinformation@redirectupdatepage')->name('/all.update-profile');
Route::post('/all/update-profile', 'personalinformation@store');

my controller's code :

    public function store(Request $request)
{
    $modal = User::create($request->all());
    return $modal;
}

Thanks.



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2s5rLvC
via IFTTT

ImageMagick works in controllers but "not available" in queues?

I've just about lost my mind trying to fix this one. I'm using ImageMagick in my controllers, and it's working okay. I've now tried to move some of those functions to a queued job, and it's now saying "ImageMagick module not available with this PHP installation."

Move them back, everything works again. Put them into a Job, everything breaks.

I'm not sure what context I could supply, really. I'm importing Image and Imagick the same in both the controllers and the jobs:

use Intervention\Image\ImageManagerStatic as Image;
use Imagick;

Image::configure(['driver' => 'imagick']);

Works fine in the controller (and helper functions), but dies here in jobs:

$preview = Image::make($file);

Identical code, aside from that. Is there any other info that could be of use?



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2F0CxM8
via IFTTT

Syntax error when adding font in laravel/html2pdf app?

Installing laravel 5.7 I convirt html code into pdf using "spipu/html2pdf": "^5.2" and got error :

syntax error, unexpected '>=' (T_IS_GREATER_OR_EQUAL), expecting end of file

when I try to attach DejaVu Sans font to my app I use this font in html in source code, like

style="font-family: 'DejaVu Sans'

My control :

    $pdf_content= !empty($requestData['pdf_content']) ? $requestData['pdf_content'] : '';
    $pdf_filename= !empty($requestData['pdf_filename']) ? $requestData['pdf_filename'] : '';
    $page_orientation = 'P';/* P or Portrait (default) L or Landscape */
    $page_format = 'A4'; // A4  A6

    $page_lang = 'en';
    $page_unicode = true;
    $page_encoding = 'UTF-8';
    $page_margins = array(5, 5, 5, 8);
    $page_pdfa = false;

    $html2pdf = new Html2Pdf(  $page_orientation, $page_format, $page_lang, $page_unicode, $page_encoding, $page_margins, $page_pdfa  );


    $html2pdf->addFont(  'DejaVu Sans', '', public_path('/fonts/DejaVuSans/DejaVuSans-Bold.ttf')  );


    $html2pdf->addFont(  'courier'  );
    $html2pdf->addFont(  'helvetica'  );
    $html2pdf->addFont(  'symbol'  );
    $html2pdf->addFont(  'times'  );
    $html2pdf->writeHTML( $pdf_content );

    $html2pdf->output($pdf_filename, 'D');

But that is not syntax error of my application anyway, if to comment line

    $html2pdf->addFont(  'DejaVu Sans', '', public_path('/fonts/DejaVuSans/DejaVuSans-Bold.ttf')  );

there is no error and pdf file is generated, but area with DejaVu Sans font is black, I suppose that is because the DejaVu Sans font is not found in the app. That how error looks on my side : https://imgur.com/a/vuGWUPp

Why error and how to fix it ?

Thanks!



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2TllhEj
via IFTTT

Retrieving session data from Laravel users from the console

Due to a bug, some data was not recorded from the session at the time a user logged in the first time. That sessions data is still there and needs to be recorded in the appropriate places in the database.

Is there any way to retrieve user session data using the information from the users table while in the console?

The sessions are handled by Redis.



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2Qh5Pai
via IFTTT