lundi 21 décembre 2020

[Vue warn]: Error in v-on handler: "Error: Request handler instance not found" Vue.js

I'm using vue-social auth package for google login

Link: https://www.npmjs.com/package/vue-social-auth

As i press the login button i'm getting:

[Vue warn]: Error in v-on handler: "Error: Request handler instance not found"

Here is the way i'm using it:

app.js

import VueSocialauth from 'vue-social-auth'
Vue.use(VueSocialauth, {
 
  providers: {
    google: {
      clientId: 'XXXXXXXXXX.apps.googleusercontent.com',
      redirectUri: 'auth/google/callback' // Your client app URL
    }
  }
})

View.vue.js

 <button @click="AuthProvider('google')">auth Google</button>

method:

 AuthProvider(provider) {
 
              var self = this
 
              this.$auth.authenticate(provider).then(response =>{
 
                self.SocialLogin(provider,response)
 
                }).catch(err => {
                    console.log({err:err})
                })
 
            },
 
            SocialLogin(provider,response){
 
                axios.post('/sociallogin/'+provider,response).then(response => {
 
                    console.log(response.data)
 
                }).catch(err => {
                    console.log({err:err})
                })
            },

Web-routes.js

{
  path: '/auth/:provider/callback',
  component: {
    template: '<div class="auth-component"></div>'
  }
},

api.php

Route::post('sociallogin/{provider}', 'Auth\AuthController@SocialSignup');
Route::get('auth/{provider}/callback', 'OutController@index')->where('provider', '.*');

env:

GOOGLE_ID=XXXX
GOOGLE_SECRET=XXXXX
GOOGLE_URL=https://localhost:8000/auth/google/callback

Auth Controller :

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Socialite;

class AuthController extends Controller
{
 

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Contracts\Support\Renderable
     */
    public function SocialSignup($provider)
    {
        // Socialite will pick response data automatic 
        $user = Socialite::driver($provider)->stateless()->user();
 
        return response()->json($user);
    }
}


via Chebli Mohamed

add and sort two array in php [closed]

i have following two arrays, like

{
  "data": [
    {
      "filename": "a.jpg"
    },
    {
      "filename": "b.jpg"
    },
    {
      "filename": "c.jpg"
    },
  ],

  "video": [
    {
      "url": "a.mp4"
    },
    {
      "url": "b.mp4"
    }
  ],
}

and i need like this

{
  "data": [
        {
          "filename": "a.jpg"
        }
   ],

   "video": [
        {
          "url": "a.mp4"
        }
    ],
    "data": [
        {
          "filename": "b.jpg"
        }
    ]

    "video": [
        {
          "url": "b.mp4"
        }
    ],

    "data": [
        {
          "filename": "c.jpg"
        },
    ],

    "video": [
        {
          "url": "a.mp4"
        }
    ],  
}

after each data[] i want video[]. video array shoud be repeat if they have limit. is it possible to write code for this type array.

i know this is too much complicated , but i really dont understand how can i write code for this array.



via Chebli Mohamed

laravel 5.3 ...Como puedo solucionar este error ErrorException in HomeController.php line 45: compact(): Undefined variable: my_denuncias [closed]

mi homecontroller donde se hace mencion a lo que se va ver en la vista de cada nivel de cliente soporte y administrador solo que no estoy pudiendo pasar por el problema que se ve de ErrorException in HomeController.php line 45:compact(): Undefined variable: my_denuncias tengo en mi repositorio el trabajo para ver mas de cerca y si alguno puede darme una salida se lo agradeceria


namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Category;
use App\Denuncia;
use App\ProjectUser;

class HomeController extends Controller
{

    public function __construct()
    {
        $this->middleware('auth');
    }

    public function index()
    {
        $user = auth()->user();
        $selected_project_id = $user->selected_project_id;

        if ($selected_project_id) {

            if ($user->is_support) {
                $my_denuncias = Denuncia::where('project_id', $selected_project_id)->where('support_id', $user->id)->get();

                $projectUser = ProjectUser::where('project_id', $selected_project_id)->where('user_id', $user->id)->first();

                if ($projectUser) {
                    $pending_denuncias = Denuncia::where('support_id', null)->where('level_id', $projectUser->level_id)->get();
                } else {
                    $pending_denuncias = collect(); // empty when no project associated
                }
            }

            $denuncias_by_me = Denuncia::where('client_id', $user->id)
                                        ->where('project_id', $selected_project_id)->get();
        } else {
            $my_denuncias = [];
            $pending_denuncias = [];
            $denuncias_by_me = [];
        }

        return view('home')->with(compact('my_denuncias', 'pending_denuncias', 'denuncias_by_me'));
    }
         
    public function selectProject($id)
    {
        // Validar que el usuario esté asociado con el proyecto
        $user = auth()->user();
        $user->selected_project_id = $id;
        $user->save();

        return back();
    }

}

mi home.blade donde tengo las vistas


@section('content')
<div class="panel panel-primary">
    <div class="panel-heading">Dashboard</div>

    <div class="panel-body">
        
        @if (auth()->user()->is_support)
        <div class="panel panel-success">
            <div class="panel-heading">
                <h3 class="panel-title">Denuncias asignadas a mí</h3>
            </div>
            <div class="panel-body">
                <table class="table table-bordered">
                    <thead>
                        <tr>
                            <th>Código</th>
                            <th>Categoría</th>
                            <th>Severidad</th>
                            <th>Estado</th>
                            <th>Fecha creación</th>
                            <th>Título</th>
                        </tr>
                    </thead>
                    <tbody id="dashboard_my_denuncias">
                        @foreach ($my_denuncias as $denuncia)
                            <tr>
                                <td>
                                    <a href="/ver/">
                                        
                                    </a>
                                </td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                            </tr>
                        @endforeach
                    </tbody>
                </table>
            </div>
        </div>

        <div class="panel panel-success">
            <div class="panel-heading">
                <h3 class="panel-title">Denuncias sin asignar</h3>
            </div>
            <div class="panel-body">
                <table class="table table-bordered">
                    <thead>
                        <tr>
                            <th>Código</th>
                            <th>Categoría</th>
                            <th>Severidad</th>
                            <th>Estado</th>
                            <th>Fecha creación</th>
                            <th>Título</th>
                            <th>Opción</th>
                        </tr>
                    </thead>
                    <tbody id="dashboard_pending_denuncias">
                        @foreach ($pending_denuncias as $denuncia)
                            <tr>
                                <td>
                                    <a href="/ver/">
                                        
                                    </a>
                                </td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td>
                                    <a href="" class="btn btn-primary btn-sm">
                                        Atender
                                    </a>
                                </td>
                            </tr>
                        @endforeach
                    </tbody>
                </table>
            </div>
        </div>
        @endif

        <div class="panel panel-success">
            <div class="panel-heading">
                <h3 class="panel-title">Denuncias reportadas por mí</h3>
            </div>
            <div class="panel-body">
                <table class="table table-bordered">
                    <thead>
                        <tr>
                            <th>Código</th>
                            <th>Categoría</th>
                            <th>Severidad</th>
                            <th>Estado</th>
                            <th>Fecha creación</th>
                            <th>Título</th>
                            <th>Responsable</th>
                        </tr>
                    </thead>
                    <tbody id="dashboard_by_me">
                        @foreach ($denuncias_by_me as $denuncia)
                            <tr>
                                <td>
                                    <a href="/ver/">
                                        
                                    </a>
                                </td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td>
                                    
                                </td>
                            </tr>
                        @endforeach
                    </tbody>
                </table>
            </div>
        </div>

    </div>
</div>
@endsection


via Chebli Mohamed

Laravel loop undefined variable in loop

I am trying to redirect users to a page where they can choose facilities they belong to. Super admins can view all facilities, this works perfectly. Organization admins should only view facilities they belong to. Unfortunately, this part fails, and i get an error Undefined variable: facilities despite the fact that facilities is defined, and if i run the quary, the correct result is obtained. The third part of the loop gets executed by default. Any tips/advice on what i am doing wrong in my loop will be appreciated.

group = $user->groups;            

        if($group[0]->name === 'Super Administrator') {

            $facilities = Facility::all();

        } else if($group[0]->name === 'Organization Administrator') {
        
            $org_id = $group[0]->organization_id;
            
            $facilities = Facility::where('organization_id', '=', $org_id)->get();

        } else if( (!empty($group[0]->facility)) && $group[0]->facility->count() == 1) {

            $url = $scheme . $facility->first()['subdomain'] . '.' . env('APP_DOMAIN', 'localhost.loc');

            return redirect()->away($url);

        } 

        $facilities = $facilities->unique();

The value of $group is :

  {
    "uuid": "924bd268-f97e-4570-9122-b30a6b23cf8a",
    "name": "Test Organization Admin",
    "alias": "test-organization-admin",
    "description": "Organization Administrator",
    "facility_id": 2,
    "status": 1,
    "facility": {
      "uuid": "924bcf28-63a8-4541-b54f-e480e3a7aae0",
      "name": "Test Facility",
      "organization_id": 4,
      "subdomain": "testfacility",
      "schema_name": "testfacility_2020_12_21_122917",
      "status": 1,
      "logoWeb": null,
      "logoWebMenu": null
    }
  }
]                                                                                                    ```


via Chebli Mohamed

dimanche 20 décembre 2020

How to check each row with foreach loop using Laravel

Lets start from a scenario. In my project there are products coming from product table and users as requester are able to request for the product but requester can request a product only one time If requester already requested for the product it will redirect back with error message otherwise the product will add to his request list.

For that i make request table having requester id and product id as foreign key. Here is request controller.The condition only check the first row of the table and not working properly.

Guide me what i am doing wrong??

 public function show($id)
{
    $request_item = new request_item; 
    $loginuser=Auth::user()->id;
    $checkif=DB::select('SELECT * FROM `request`');
    $requester_ID = DB::table('requester')->where('user_id', $loginuser)->value('id');

       foreach ($checkif as $db) 
        {

           if ($requester_ID==$db->requester_id && $id==$db->product_id) {
               
                return redirect()->back()->with('error_code', 5);
            }
            else
            {
                  $requester_ID = DB::table('requester')->where('user_id', $loginuser)->value('id');
                  $request_item->requester_id = $requester_ID;
                  $request_item->product_id = $id;
                  $request_item->save();
                return redirect('myRequest');
                
            }
        }     
        return "Something went wrong! Please try gain later";

      
     
     //return view('myRequest');
}


via Chebli Mohamed

Laravel returning IP address for assets instead of domain

I'm trying to set up a local Laravel Homestead (5.3) environment for my API. I want to be able to hit the API locally through my Android app.

I've set everything up, including getting the Android app to trust the server's certificate, but now I'm getting the following issue:

The app trusts my server's domain (in my case, homestead.test). The problem is, my server is returning all assets with the IP address of the server, which is 192.168.10.10, so all assets return in the form of:

https://192.168.10.10/storage/img/posts/6/thumbnails/1.jpeg

For whatever reason, the Android app doesn't trust this IP as I guess I don't have the certificate for it set up. Instead, I need it to return with the domain, homestead.test, so it looks like:

https://homestead.test/storage/img/posts/6/thumbnails/1.jpeg

In my hosts file (Windows), I have this already:

192.168.10.10  homestead.test

How can I make this change? I've tried changing APP_URL to https://homestead.test in the .env file, but that doesn't seem to have changed anything.

What am I missing?



via Chebli Mohamed

How to add offset after sortBy in laravel

How can I add offset after using sortBy in laravel? Please see my code below.

Controller

$order_type = ($dir == 'asc') ? 'sortBy' : 'sortByDesc';

$inventories = $inventories->get()->$order_type(function($inventory) {
   $item_status = [
     '0'  => 'I',
     '1'  => 'D',
     '2' => 'HI',
     '3' => 'HR',
     '4' => 'A',
     '5' => 'DS'
   ];

   return $item_status[$inventory->receive_item->inspection_status];
});

$inventories = $inventories->offset($start)->limit($limit);

Error I get

BadMethodCallException in Macroable.php line 74: Method offset does not exist.



via Chebli Mohamed