mercredi 22 juillet 2020

Laravel-5 SMTP mail

There isnt any error but dont send email this code. Why ?

public function sendEmailReminder() {

    `enter code here`Mail::send([],[],function($message){
    $message->from('destek@crm.gen.tr', 'Your Application');

    $message->to('birgul@laysos.com.tr')->subject('Your Reminder!');
   });

    return back()->with('success','email gönderildi');
}


via Chebli Mohamed

mardi 21 juillet 2020

Laravel: fwrite(): send of 18 bytes failed with errno=10054 An existing connection was forcibly closed by the remote host

I am trying to make the "forgot password" function work on Laravel. I am using mailtrap. it was working fine a couple of weeks ago but now it shows me this error that an existing connection was forcibly closed by the remote host. please help

enter image description here



via Chebli Mohamed

How to pass dynamic table name to model according user's input in Laravel

I have a project that the column_field is dynamic, it's generated according to the user's input. Now I want to set that table dynamically, according to the user's input also. And is this possible without doing php artisan migrate?

Here what I want to do inside my Model.

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Customer extends Model
{
    $tableName = 'users_input';

    protected $guarded = [];
    protected $table = $tableName;
    public $timestamps = false;
    protected $primaryKey = 'id';
}

Waiting for your suggestions.

Cheers



via Chebli Mohamed

Laravel API: Product filtering and sorting together

I want to filer product list and sort it too. I have 2 tables for product data.

Products -> [id, name, description, point, data, etc.]

in this table, data is a json object. This object contains all the specifications of a product. Ram, Camera, storage etc. I want to filter data using these specs too. Filter using ram for example.

Prices -> [id, porduct_id, link, price]

one product can have multiple prices but i need to filter using only minimum price. And if I want to sort it, minimum price will be considered for sorting.

I have implemented code for filter. But I'm stuck at implementing sort after filter. Price range filter with sorting by price seems difficult for me. can anyone help me out?

Current code for price range filter

        if (isset($filters['price'])) {
            $product = $product->whereHas('prices', function ($query) use ($filters) {
                $query->whereBetween('price', [$filters['price']['min'], $filters['price']['max']]);
            });
        }

Current code for other data filters:

        if ($request->has('filters') && !empty($filters = $request->get('filters'))) {
            $product = $product->filter($request->get('filters'));
        }

Current code for sorting by price

        if ($request->has('price')) {
            $direction = in_array($request->query('price'), ['asc', 'desc']) ? $request->query('price') : 'asc';

            return ProductResource::collection(
                $product
                    ->addSelect(['min_price' => Price::select('price')
                        ->whereColumn('product_id', 'products.id')
                        ->oldest('price')
                        ->take(1)
                    ])
                    ->orderBy('min_price', $direction)
                    ->paginate(self::PAGINATE_NUMBER)
            );
        }

I'm stuck at doing both of these operation together. If you need more info about this question, please comment.



via Chebli Mohamed

How to check an array value is available in session array in laravel?

How to check an array value is available in session array in laravel?

My Seesion array look like

Array ( 
       [0] => Array ( 
                     [id] => qwewa,
                     [prod_name] => p1
                    ) 
       [1] => Array ( 
                     [id] => asdsa,
                     [prod_name] => p2
                    )
      )

i want to check whether a particular id is available in my session array or not. i tried with pluck, has, data get

Suggest me how to in_array function in laravel effectively.



via Chebli Mohamed

Laravel same code was working but now giving "Found empty contents" error

here is my log data

#0 /home/path/to/project/vendor/simplesoftwareio/simple-qrcode/src/SimpleSoftwareIO/QrCode/BaconQrCodeGenerator.php(74): BaconQrCode\Writer->writeString(NULL, 'ISO-8859-1', 1)

#1 /home/path/to/project/app/Http/Controllers/TicketDPController.php(1405): SimpleSoftwareIO\QrCode\BaconQrCodeGenerator->generate(NULL)

#2 [internal function]: App\Http\Controllers\TicketDPController->ImplementationSheetPDF('62374')

#3 /home/path/to/project/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): call_user_func_array(Array, Array)

#4 /home/path/to/project/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(45): Illuminate\Routing\Controller->callAction('ImplementationS...', Array)

#5 /home/path/to/project/vendor/laravel/framework/src/Illuminate/Routing/Route.php(212): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(App\Http\Controllers\TicketDPController), 'ImplementationS



via Chebli Mohamed

I need help whit laraver

Hello why i get this error?

I need small help!

There is Error code!

ErrorException Invalid argument supplied for foreach() (View: F:\server\htdocs\yii\yumypizza\resources\views\shop\shopping-cart.blade.php)

here is my code from shop.shopping-cart

@extends('layouts.master')

@section('title')

THE YUMMI PIZZA
@endsection
@section('content')
  @if(Session::has('cart'))

   <div class="row">
        <div class="col-sm-6 col-md-6 col-md-offset-3 col-sm-offset-3">
            
            <ul class="list-group">
                    @foreach($products as $product)
                    <li class="list-group-item">

                        <span class="badge"></span>
                        <strong></strong>
                        <span class="label label-success"></span>

                        <div class="btn-group">
                            <button type="button" class="btn btn-primary btn-xs dropdown-toogle" data-toggle="dropdown">Action <span class="caret"></span></button>
                            <ul class="dropdown-menu">
                                <li><a href="">Reduce by 1</a></li>
                                <li><a href="">Reduce All</a></li>
                            </ul>
                        </div>

                    </li>
                    @endforeach
            </ul>
            
        </div>
   </div>
   <div class="row">
    <div class="col-sm-6 col-md-6 col-md-offset-3 col-sm-offset-3">
        <strong> Total: </strong>
   
        </div>
   </div>
   <hr>
   <div class="row">
    <div class="col-sm-6 col-md-6 col-md-offset-3 col-sm-offset-3">
        <button type="button" class="btn btn-success">CheckOut</button>
   
        </div>
   </div>
@else
<div class="row">
    <div class="col-sm-6 col-md-6 col-md-offset-3 col-sm-offset-3">
        <h2>No Items in Cart!</h2>
</div>
</div>
@endif
@endsection

and here is my controller function code.

public function getCart() {
        if (!Session::has('cart')) {
            return view('shop.shopping-cart', ['products' => null]);
        }
        $oldCart = Session::get('cart');
        $cart = new Cart($oldCart);
        return view('shop.shopping-cart', ['products' => $cart->items, 'totalPrice' => $cart->totalPrice]);
     } 
}

and Route.

    Route::get('/add-to-cart/{id}', [
        'uses' => 'ProductController@getAddToCart',
        'as' => 'product.addToCart'


]);

Route::get('/shopping-cart', [
    'uses' => 'ProductController@getCart',
    'as' => 'product.shoppingCart'


]);

If you can help me about this !



via Chebli Mohamed