jeudi 6 mai 2021

I'm getting an error displaying the user's profile photo on laravel 7

public function index(Request $request)
{
    $data = Admin::when($request->keyword, function ($query) use ($request) {
        $query->where('nama_lengkap', 'like', "%{$request->keyword}%");
    })->paginate(5);

    $data->appends($request->only('keyword'));

    return view('admin.crud_admin.index', compact('data'));
}

Model Admin.php

protected $fillable = [
    'avatar', 'nama_lengkap', 'email', 'password',
];

public function getAvatar()
{
    if (!$this->avatar) {
        return asset('images/default.png');
    }

    return asset('images/' . $this->avatar);
}

index.blade.php

<a class="nav-link dropdown-toggle dropdown-user-link" id="dropdown-user" href="javascript:void(0);"
   data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
    <div class="user-nav d-sm-flex d-none">
        <span class="user-name font-weight-bolder"></span>
        <span class="user-status">Admin</span>
    </div>
    <span class="avatar"
        ><img class="round" src=""
          alt="avatar" height="40" width="40"
        /><span class="avatar-status-online"></span>
    </span>
</a>

this does not appear even there is an error:

"Method Illuminate\Database\Eloquent\Collection::getAvatar does not exist. (View: C:\xampp\htdocs\Helpdesk\resources\views\admin\crud_admin\index.blade.php)"

Can you help me? please this is important to me



via Chebli Mohamed

Locale Get Ignored When Sending Mail with Queue

I'm looking for an answer. Laravel Framework 5.5.44 and I have a queue that will send an email whenever someone place new order on my website. I used event and listener to accomplish this. My queue successfully sent the email but my locale code does not working. Below is my code :

NewOrderListener.php

 public function handle($event)
    {
        

        try {
            dump('new order registered (listernerrr)');

            // dump($event->order);

            $email = $event->order['email'];
            // $logo_settings_details = Settings::get_logo_settings_details();
            // // dump($logo_settings_details);
            // $event->order->prepend('logo_settings_details', DB::table('gr_logo_settings')->get());
            // array_push($event->order, DB::table('gr_logo_settings')->get());
            $event->order['logo_settings_details'] = DB::table('gr_logo_settings')->get();
            // $data = [
            //     'logo_settings_details' => DB::table('gr_logo_settings')->get(),
            // ];
            // dd($data);
            $get_images = DB::table('gr_no_images')->select('banner_image','restaurant_store_image','restaurant_item_image','product_image','logo_image','landing_image','shop_logo_image','category_image')->first();
            if(empty($get_images) === false)
            { 
                $no_item = $get_images->restaurant_item_image;
                $event->order['no_item'] = $no_item;

            }

            
            $this->general_setting = DB::table('gr_general_setting')->get();
            if(count($this->general_setting) > 0){
                foreach($this->general_setting as $s){
                    $event->order['FOOTERNAME'] = $s->footer_text;  
                }
            }
            else {
                 $event->order['FOOTERNAME'] = 'ePickMeUp';
            }
            

            // dd($event->order);

            Mail::send('email.order_mail_customer', $event->order, function($message) use($email)
            {
                dump($email);
                // $sub_data = (Lang::has(Session::get('front_lang_file').'.FRONT_ORDER_SUCCSESS')) ? trans(Session::get('front_lang_file').'.FRONT_ORDER_SUCCSESS') : trans($this->FRONT_LANGUAGE.'.FRONT_ORDER_SUCCSESS');

                // dump($sub_data);

                $message->to('googleadmin@gmail.com')->subject('SUCCESSFUL ORDER 😍');
                dump('email sent');

            });

        } catch (\Exception $e) {
            // Log Error
            // Log::error($e->getMessage());

            // Sent Error To Slack

            // Dump Error
            dump($e->getMessage());
        }

    }

order_mail_customer.blade.php

    <td style="border-top: 5px solid #f7d501;">
        <table style="padding:10px;width:100%;">
            <tr>
                <td align="center">
                    @php $path = url('').'/public/images/noimage/default_image_logo.jpg'; @endphp
                    @if(count($logo_settings_details) > 0)
                    @php
                        foreach($logo_settings_details as $logo_set_val){ }
                    @endphp
                    @if($logo_set_val->admin_logo != '')
                        @php $filename = public_path('images/logo/').$logo_set_val->admin_logo; @endphp 
                        @if(file_exists($filename))
                        @php $path = url('').'/public/images/logo/'.$logo_set_val->admin_logo; @endphp
                        @endif
                    @endif                          
                    @endif
                    <img src="" alt="@lang(Session::get('front_lang_file').'.ADMIN_LOGO')" class="img-responsive logo"  width="100">
                </td>                       
            </tr>
        </table>
        </td>
    </tr>
    
    @if($self_pickup==1)
        <tr>
            <td>
                <table style="width:100%;background:url('')no-repeat; padding:56px 20px;">
                    <tr>
                        <td colspan="1" style="text-align:center; font-family:cursive; font-size:35px; padding-bottom: 20px;  color: #fff;">
                            @lang(Session::get('front_lang_file').'.FRONT_THANK_ORDER')
                        </td>                           
                    </tr>
                    <tr>
                        <td style="text-align:center; font-family:sans-serif; font-size:17px; padding-bottom: 20px;  color: #fff; line-height: 25px;">
                            @lang(Session::get('front_lang_file').'.API_ORDER_PLACED')
                            
                        </td>
                    </tr>
                    <tr>
                    <td style="text-align:center; font-family:sans-serif; font-size:17px; padding-bottom: 20px;  color: #fff; line-height: 25px;">
                        @lang(Session::get('front_lang_file').'.ADMIN_TRANSACTION_ID')&nbsp;:&nbsp;
                    </td>
                </tr>
                </table>
            </td>
        </tr>

Why all those @lang(Session::get('front_lang_file') not getting called on queue? Hopefully, someone could help me to solve this problem. Thanks in advance.



via Chebli Mohamed

mercredi 5 mai 2021

how to use component in Laravel 6.x

I would like to make a component.

However It does not work.

I tried to @component('components.pulldown')@endcomponent however , it happnens 500 error.

so I used @exntend instead.

but it only displays upper side of the page.

    @foreach ($users as $user)
    <tr>
        <td></td>
        <td></td>
        @if($user->country)
        <td></td>
        @else
        <td>Select  @extends('components.pulldown') </td>
        @endif
    </tr>
    @endforeach

<select name="countries">
<option value="US">US</option>
<option value="UK">UK</option>
<option value="EU">EU</option>
<option value="JP">Japan</option>
</select>


via Chebli Mohamed

full text search is not working on live server in laravel

I have added full-text search in my histories table. It is working fine on local machine but on live server is giving error after taking long time. Error is here

504 Gateway Time-out

My migration for full text search

     DB::statement('ALTER TABLE histories ADD FULLTEXT search(model)');
    $table->engine = 'MyISAM';

And this is how i am trying to use it

$histories->whereRaw("MATCH(model) AGAINST(? IN BOOLEAN MODE)", $strtable)

What could be the issue. Please guide



via Chebli Mohamed

Laravel with multiple custom paginations

I made a custom Laravel pagination but dashboard isn't with the same styling , So I wanna make another one.



via Chebli Mohamed

mardi 4 mai 2021

Laravel HTML form issue

 <form action="/group/{id}/save/group" method="POST">
    @csrf                              
       <table id="modal-table">                                      
         @foreach($user_list->get() as $f)
           <tr>
              <td>
                 <div class="image">
                    @if($f->follower->avatar_location)  
                        <img src="" class="img-circle" style="max-height:50px;" />
                    @else
                        <img src="/assets/media/icons/socialbuttons/user.png" class="img-circle" style="max-height:50px;"/>
                    @endif
                 </div>
                 <div class="detail">                       
                 @if($f->follower->verified == 1)
                    <img id="verified_img_sm_mess_list" src="/assets/media/icons/socialbuttons/octagonal_star.png" alt="Recensioni">
                 @else
                    </h3>
                 @endif  
                    <small id="mess_list_uname">@</small>
                 </div>
                 <input name="group" value="">
                 <input name="person" value="">
                 <button type="submit" class="btn-link">Go</button>
             </td>
          </tr>
      @endforeach
    </table>
  </form>

Hey a small problem! in the Foreach loop and every member in the list, I tried some bare-bones to get each users id and hobby id (to add to database, but that's not important). For some reason, when I take the input 'name' and click the Go button, All "id's" of everyone in the list are executed, Not the individual id of each user. Meaning.. each user displays their individual id and a go button, but click go and all id's are collected, not just one. It's probably really obvious but any ideas why this is happening?? Thanks!



via Chebli Mohamed

How to disable/override $with attribute in Laravel models

I have this model:

class Payment extends MyBaseModel
{  
    protected $table = 'payments';
    protected $with = ['company', 'account', 'manager', 'block', 'network'];
    protected $appends = ['someAttribute', 'someOtherAttribute'];

   ...
}

In another model I have a relation that looks like this:

public function payment() {
      return $this->belongsTo('App\Payment', 'payment_id', 'id')->withTrashed();
}

What I need is to be able to, sometimes, retrieve $this->payment without all the the relationships specified in $with (i.e. company, account, manager, block, network) also would like to (sometimes) disable the appended attributes.

Can't find a way to accomplish that.



via Chebli Mohamed