Issues (29)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Http/Controllers/AdminController.php (9 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Devfaysal\LaravelAdmin\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
use Yajra\DataTables\DataTables;
7
use Spatie\Permission\Models\Role;
8
use Illuminate\Support\Facades\Hash;
9
use Illuminate\Support\Facades\Session;
10
use Devfaysal\LaravelAdmin\Models\Admin;
11
use Spatie\Permission\Models\Permission;
12
use Illuminate\Foundation\Bus\DispatchesJobs;
13
use Illuminate\Routing\Controller as BaseController;
14
use Illuminate\Foundation\Validation\ValidatesRequests;
15
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
16
17
class AdminController extends BaseController
18
{
19
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
20
21
    public function index()
22
    {
23
        $admins = auth()->user()->hasPermissionTo('manage_trashed_admins', 'admin') ? Admin::withTrashed()->get() : Admin::all();
0 ignored issues
show
The method user does only exist in Illuminate\Contracts\Auth\Guard, but not in Illuminate\Contracts\Auth\Factory.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
The method get does only exist in Illuminate\Database\Eloq...\Database\Query\Builder, but not in Illuminate\Database\Eloquent\SoftDeletes.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
24
25
        return view('laravel-admin::admins.index', [
26
27
            'admins' => $admins
28
29
        ]);
30
    }
31
32
    public function show(Admin $admin)
33
    {
34
        return view('laravel-admin::admins.show', [
35
36
            'admin' => $admin
37
38
        ]);
39
    }
40
41 View Code Duplication
    public function create()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
42
    {
43
        $permissions = Permission::where('guard_name', 'admin')->get();
44
        $roles = Role::where('guard_name', 'admin')->get();
45
        return view('laravel-admin::admins.create', [
46
            'roles' => $roles->pluck('name'),
47
            'permissions' => $permissions->pluck('name')
48
        ]);
49
    }
50
51
    public function store(Request $request)
52
    {
53
        $request->validate([
0 ignored issues
show
The call to validate() misses a required argument $...$params.

This check looks for function calls that miss required arguments.

Loading history...
54
            'name' => 'required',
55
            'email' => 'required|email|unique:admins',
56
            'password' => 'required',
57
        ]);
58
59
        $admin = Admin::create([
60
            'name' => $request->name,
61
            'email' => $request->email,
62
            'password' => Hash::make($request->password),
63
        ]);
64
        
65
        if($request->roles){
66
            $admin->assignRole($request->roles);
67
        }
68
69
        if($request->permissions){
70
            $admin->givePermissionTo($request->permissions);
71
        }
72
        
73
74
        Session::flash('message', 'Admin created Successfully!!'); 
75
        Session::flash('alert-class', 'alert-success');
76
77
        return redirect('/admin/admins');
78
    }
79
80 View Code Duplication
    public function edit(Admin $admin)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
81
    {
82
        $permissions = Permission::where('guard_name', 'admin')->get();
83
        $roles = Role::where('guard_name', 'admin')->get();
84
        return view('laravel-admin::admins.edit', [
85
            'admin' => $admin,
86
            'roles' => $roles->pluck('name'),
87
            'permissions' => $permissions->pluck('name')
88
        ]);
89
    }
90
91
    public function update(Request $request, Admin $admin)
92
    {
93
        $attributes = $request->validate([
0 ignored issues
show
The call to validate() misses a required argument $...$params.

This check looks for function calls that miss required arguments.

Loading history...
94
            'name' => 'required',
95
            'email' => 'required|email|unique:admins,email,' . $admin->id
96
        ]);
97
98
        if($request->password){
99
            $attributes['password'] = Hash::make($request->password);
100
        }
101
102
        $admin->update($attributes);
103
104
        if($request->roles){
105
            $admin->syncRoles($request->roles);
106
        }
107
        if($request->permissions){
108
            $admin->syncPermissions($request->permissions);
109
        }
110
        
111
        Session::flash('message', 'Admin updated Successfully!!'); 
112
        Session::flash('alert-class', 'alert-success');
113
114
        return redirect('/admin/admins');
115
    }
116
117
    public function destroy(Admin $admin)
118
    {
119
        $admin->delete();
120
121
        Session::flash('message', 'Admin deleted Successfully!!'); 
122
        Session::flash('alert-class', 'alert-success');
123
124
        return redirect('/admin/admins');
125
    }
126
127
    public function restore($id)
128
    {
129
        $admin = Admin::withTrashed()->findOrFail($id);
0 ignored issues
show
The method findOrFail does only exist in Illuminate\Database\Eloquent\Builder, but not in Illuminate\Database\Eloq...\Database\Query\Builder.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
130
        $admin->restore();
131
132
        Session::flash('message', 'Admin restored Successfully!!'); 
133
        Session::flash('alert-class', 'alert-success');
134
135
        return redirect('/admin/admins');
136
    }
137
138
    public function datatable()
139
    {
140
        $admins = auth()->user()->hasPermissionTo('manage_trashed_admins', 'admin') ? Admin::withTrashed()->get() : Admin::all();
0 ignored issues
show
The method user does only exist in Illuminate\Contracts\Auth\Guard, but not in Illuminate\Contracts\Auth\Factory.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
The method get does only exist in Illuminate\Database\Eloq...\Database\Query\Builder, but not in Illuminate\Database\Eloquent\SoftDeletes.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
141
142
        return DataTables::of($admins)
143
            ->addColumn('action', function($admin) {
144
                $string = '';
145
                if($admin->trashed()){
146
                    $string .= '<a class="btn btn-sm btn-oval btn-warning" href="'. route('admins.restore', $admin->id) .'">Restore</a> ';
147
                }
148
                $string .= '<a class="btn btn-sm btn-oval btn-info" href="'. route('admins.edit', $admin->id) .'">Edit</a>';
149
                $string .= ' <a class="btn btn-sm btn-oval btn-primary" href="'. route('admins.show', $admin->id) .'">Show</a>';
150
                return $string;
151
            })
152
            ->addColumn('roles', function($admin) {
153
                $string = '';
154
                foreach ($admin->roles as $role){
155
                    $string .= '<span class="badge badge-success">'. $role->name .'</span> ';
156
                }
157
                return $string;
158
            })
159
            ->addColumn('last_login_at', function($admin) {
160
                return $admin->last_login_at ? '<span class="badge badge-success">' . $admin->last_login_at->format('d M Y h:i:s A') . '</span>' : '<span class="badge badge-warning">Never Logged In</span>';
161
            })
162
            ->rawColumns(['action', 'roles', 'last_login_at'])
163
            ->make(true);
164
    }
165
}
166