mardi 25 août 2020

Laravel nova File Field | How can i get resource id before storing file

I want to store a file with resource id + extension i.e 1.csv,2.csv,3.txt,4.jpeg.

I am using laravel nova File Field to upload file in s3 is there any way I can get the id of that row before storing in db?

below is the code I am using to uploading files.

File::make('path')
    ->disk(config('filesystems.default'))
    ->rules('required','mimes:csv,txt')
    ->storeAs(function (Request $request) {
        return $request->path->getClientExtension();
    })
   ->path('csv'),


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

email notification in laravel 5.5 i get this error ```Trying to access array offset on value of type null```

i want to get email notification each time a new user is registered but after creating php artisan make:notification Taskcompleted and added Notification::route('mail','admin@gmail.com')->notify(new TaskCompleted()); like this in my contoller

public function store(Request $request){
        $employee = request()->validate([
            'employee_id' => 'required|max:250',
            'name' => 'required|max:100',
            'place_of_birth' => 'nullable|max:100',]);
Notification::route('mail','admin@gmail.com')->notify(new TaskCompleted());

i keep getting this error Trying to access array offset on value of type null i have imported the necessary class and configured my .env file with mailtrap,still yet same error



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

Laravel Clousure

I keep getting this Opis\Closure\ClosureStream::stream_set_option is not implemented! when I'm running a closure using the dispatch helper.

        dispatch(function () use ($done) {
            foreach ($done as $order) {
              try{
                Log::info("Some code");
              }catch(\Exception $e){
                continue;
              }
            }
        });

It's been years since I've worked with PHP and I'm really stuck on this part.

I'm using vagrant with laravel 5.8 and my PHP 7.4.

Thanks in advance guys.



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

Laravel - Many To Many return child records filtered

I have a User model which has a M:M relationship with Role model (I use roles_user intermediate table for M:M relationship)

The intermediate table has a column "Active" which defines which of the multiple roles assigned to a User is the active one.

So, I'm trying to retrieve a User with all the relationships it has an also only the active role.

For that, Im executing the follwing code https://laravel.com/docs/6.x/eloquent-relationships#querying-relationship-existence :

public function index()
    {    
        $users = User::whereHas('roles', function (Builder $query) {
            $query->where('active', true); 
        })->get();            
        foreach ($users as $user) {
            dd($user->roles);
        }
        
        return view('pages.admin.users.index', compact('users'));
    }

When I dd the collection, I have the 5 records in intermnediate table and not just the active one wich I'm filtering:

enter image description here

enter image description here

What I am doing wrong?

Regards



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

Issue implementing google autocomplete in vue.js

I'm trying to use google auto complete in vue.js with laravel but it is giving me error :

[Vue warn]: Error in mounted hook: "ReferenceError: google is not defined" 
found in
---> <VueGoogleAutocomplete> at /src/components/VueGoogleAutocomplete.vue
       <App> at /src/App.vue

         <Root>

here is the link to the code which i'm trying to implement:

https://codesandbox.io/s/nifty-bardeen-5eock



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

laravel 5.8 bootstrap not working inside Jquery

i am using https://developer.snapappointments.com/bootstrap-select/examples/

its working fine in view but when i using this in Jquery below code its not working. help me to fix this.

view code php

      <table id="tableAppointment" style="background-color:powderblue;">
     
        <tr>
        <th style="text-align:center;" colspan="1">NAME</th>
        <th style="text-align:center;" colspan="1">HSN/SAC</th>
       
       
      <th><a href="#" class="addRow btn btn-warning vertical-center"><i class="glyphicon glyphicon- 
  plus">ADD</i></a></th>
      </tr>
       
       <tr>
        <td >
    
            <select class="selectpicker" data-live-search="true"  name="product_name[]">
           <option value=""></option>
          @foreach ($addnewitem as $key=>$addnewitems)
            <option  ></option> 
          @endforeach </select>
    
        </td>
    
     
        <td >
              <select class="selectpicker" data-live-search="true"  name="part_no[]">
           <option value=""></option>
          @foreach ($addnewitem as $key=>$addnewitems)
            <option  ></option> 
          @endforeach </select>
    
        </td>
    
         <td><a href="#" class="btn btn-danger "><i class="glyphicon glyphicon-remove">REMOVE</i></a> 
  </td>
      </tr>
    
    </table>
    
    <script type="text/javascript">
    
        $('.addRow').on('click',function(){
            addRow();
        });
        function addRow()
        {
        
            var tr='<tr>'+
    
    
            '<td ><select class="selectpicker" data-live-search="true"  name="product_name[]"><option 
 value=""></option> @foreach($addnewitem as $key=>$addnewitems)<option  ></option>@endforeach </select></td>'+
    
    
    
             
'<td ><select class="selectpicker" data-live-search="true"  name="part_no[]"><option value=""></option> 
  @foreach($addnewitem as $key=>$addnewitems)<option  ></option>@endforeach 
 </select></td>'+
    
    
           
            
 '<td><a href="#" class="btn btn-danger remove"><i class="glyphicon glyphicon-remove">REMOVE</i></a> 
 </td>'+
         
            '</tr>';
            $('tbody').append(tr);
        };
        $('.remove').live('click',function(){
            var last=$('tbody tr').length;
            if(last==1){
                alert("you can not remove last row");
            }
            else{
                 $(this).parent().parent().remove();
            }
        
        });
    
    </script>

enter image description here



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

ReflectionException Error in Laravel 5.5 after deployment to live server

Due to unable to access Terminal in hosting server, I ran composer update in my local machine and uploaded everything including vendor folder, composer.json and composer.lock. My hosting server run PHP 7.1 and so does my local machine with Laravel 5.5.

Now I am facing PHP Fatal error: Uncaught ReflectionException: Class view does not exist in /public_html/vendor/laravel/framework/src/Illuminate/Container/Container.php:752 Stack trace:

#0 /public_html/vendor/laravel/framework/src/Illuminate/Container/Container.php(752): ReflectionClass->__construct('view')

#1 /public_html/vendor/laravel/framework/src/Illuminate/Container/Container.php(631): Illuminate\Container\Container->build('view')

#2 /public_html/vendor/laravel/framework/src/Illuminate/Container/Container.php(586): Illuminate\Container\Container->resolve('view', Array)

#3 /public_html/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(732): Illuminate\Container\Container->make('view', Array)

#4 /public_html/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php(110): Illuminate\Foundation\Application->make('view', Array)

#5 /public_html/vendor/laravel/framework/src/Illuminate/Found in /public_html/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 752

I ran the following command.

composer require maatwebsite/excel --no-update
composer update maatwebsite/excel

And I uploaded the following files and folder from local to live server.

  1. Vendor / maatwebsite folder and all other newly created by folders.
  2. vendor / composer folder
  3. composer.json
  4. composer.lock

I cleared config cache, route cache, view cache from PHP file using artisan command.

Can anyone please help me to debug the error? Thank you.



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