imposition

Experience

3,690

0 Best Reply Awards

  • Member Since 11 Months Ago
  • 23 Lessons Completed
  • 0 Favorites

29th November, 2017

imposition left a reply on CRUD Help • 9 months ago

@Snapey That's not a real problem. The user he's deleting does not affect the user that he logs in to the app.

This form deletes another type of user. A Radius one.

28th November, 2017

imposition left a reply on CRUD Help • 9 months ago

Added a href instead of button and it works fine now.

imposition left a reply on CRUD Help • 9 months ago

Okay did like this:

Route::post('newuser/delete/{id}', '[email protected]')->name('newuser.destroy');
        <td>{!! Form::open(['route' => ['newuser.destroy', $d['id']], 'method' => 'POST']) !!}
        {!! Form::submit('Excluir', ['class' => 'btn btn-default btn-sm']) !!}
        {!! Form::close() !!}</td>
 public function destroy($id)
            {
          
            $user = Users::find($id);
            $user1 = Groups::find($id);
            $user->delete();
            $user1->delete();

            return redirect('home')
            ->with('message', 'Usuário removido com sucesso!!');
            }    

It worked one time, now it does not work anymore Ç_Ç

imposition left a reply on CRUD Help • 9 months ago

Don't know how to use boot... I'm pretty new to Laravel

imposition started a new conversation CRUD Help • 9 months ago

Hi there, I need to create a method to delete a user he is registered in two diff tables Created 2 models Users , Groups

The delete button:

        <td><a href="/newuser/delete/{{ $d['Username'] }}" class="fa fa-trash" aria-hidden="true"></i></a></td>

Route:

Route::delete('newuser/delete/{d}', '[email protected]');

Controller:

public function search(Request $request)
            {
            $users = Users::search($request);
            $users1 = Groups::search($request);
            foreach ($users as $user) {
            $data[] = array('Username' => $user->username,
            'id' => $user->id
            );
            };
            foreach ($users1 as $user1){
            $data1[] = array ('id2' => $user1->id);
            };
            return view('user.buscar', compact('data'));
            }

            public function buscar()
            {
            return view ('user.buscar');
            }

            public function destroy($id)
            {
            try {
            DB::transaction(function() use($id)
            {
            $user = Users::find($id);
            $user1 = Groups::find($id);
            $user->delete();
            $user1->delete();
            });
            return redirect('home')
            ->with('message', 'Usuário removido com sucesso!!');
            }
            catch (\Exception $e) {
            return redirect('home')
            ->with('message', 'Usuário não foi removido, verifique os dados!!');
            }

            } 

HELP pls ç-ç

imposition left a reply on Transaction • 9 months ago

I was trying

DB::transaction(function($request) {

27th November, 2017

imposition started a new conversation Transaction • 9 months ago

  public function create(Request $request)
{
        try {
            DB::transaction(function() 
        {

        $user =  new Users;
        $user->username = $request->user;
        $user->attribute = "Password";
        $user->op = "==";
        $user->value = $request->password;
        $user1 = new Groups;
        $user1->username = $request->user;
        $user1->groupname = $request->group;
        $user1->save();
        $user->save();
        });

            return redirect('home')
            ->with('message', 'Usuário criado com sucesso!!');
        }
        catch (\Exception $e) {
            return redirect('home')
            ->with('message', 'Usuário não cadastrado! Verifique os dados!');
        }
}

With DB::transaction this code does not create user Without DB::transaction this code create user What am i doing wrong?

24th November, 2017

imposition left a reply on Improving Query • 9 months ago

@bobbybouwmann Added a date range picker instead of a simple date picker Now i'm not having 'lag' problems haha

imposition left a reply on Query On My Model Taking Too Much Time To Finish. • 9 months ago

Changed it to where between and added a daterangepicker instead of datepicker

imposition started a new conversation Improving Query • 9 months ago

$data = TopWireless::select(DB::raw('UserName, sum(AcctInputOctets) as Input , sum(AcctOutputOctets) as Output'))
                    ->whereDate('AcctStartTime' , 'regexp', date($data['date']))->groupBy('UserName')->orderBy('Output', 'desc')->limit(20)->get();

I'm wondering how to improve this query. This is taking too much time to complete.

22nd November, 2017

imposition left a reply on Query On My Model Taking Too Much Time To Finish. • 9 months ago

@mattsplat The AcctStartTime is a date. I'm searching through my DB with just the year and the month. After reading what you both said i did the code like this:

            $data = TopFiber::select(DB::raw('UserName, sum(AcctInputOctets) as Input , sum(AcctOutputOctets) as Output'))
                    ->whereDate('AcctStartTime' , $data['date'])->groupBy('UserName')->orderBy('Output', 'desc')->limit(20)->get();

And is taking a lot of time yet

21st November, 2017

imposition left a reply on Query On My Model Taking Too Much Time To Finish. • 9 months ago

@mattsplat Added index to AcctStartTime and its getting a little less longer .... But not less enough

20th November, 2017

imposition left a reply on Query On My Model Taking Too Much Time To Finish. • 10 months ago

@mattsplat

   {#766
       +"Table": "radacct",
       +"Non_unique": 1,
       +"Key_name": "AcctStartTime",
       +"Seq_in_index": 1,
       +"Column_name": "AcctStartTime",
       +"Collation": "A",
       +"Cardinality": 8576707,
       +"Sub_part": null,
       +"Packed": null,
       +"Null": "",
       +"Index_type": "BTREE",
       +"Comment": "",
       +"Index_comment": "",

19th November, 2017

imposition left a reply on Query On My Model Taking Too Much Time To Finish. • 10 months ago

AcctStartTime is the date, I think This is taking too much time cus i have over 50.000 entries to This table

18th November, 2017

imposition started a new conversation Query On My Model Taking Too Much Time To Finish. • 10 months ago

Hi there! I have this query inside my model:

            $data = TopFiber::select(DB::raw('UserName, sum(AcctInputOctets) as Input , sum(AcctOutputOctets) as Output'))
                    ->where('AcctStartTime' , 'LIKE', $data['date'] . '%')->groupBy('UserName')->orderBy('Input', 'desc')->limit(20)->get();

But this is taking too much time like 5 minutes to complete or so. Can i do this any other way to speed up the query ? I need this exactly like it is.

17th November, 2017

imposition left a reply on Formatting To Eloquent • 10 months ago

Got it!

$data = TopFiber::select(DB::raw('UserName, sum(AcctInputOctets) as Input , sum(AcctOutputOctets) as Output'))
                    ->where('AcctStopTime' , 'LIKE', $data['date'] . '%')->groupBy('UserName')->orderBy('Input', 'desc')->limit(20)->get();

imposition started a new conversation Formatting To Eloquent • 10 months ago

SELECT Username, SUM(AcctInputOctets) Input, SUM(AcctOutputOctets) Output
FROM radacct WHERE AcctStopTime LIKE '%xxxx%'  GROUP BY username ORDER BY Input DESC limit 20;

Please can someone help me format this to Eloquent? Like :

select(DB::raw('sum(AcctInputOctets) as Input , sum(AcctOutputOctets) as Output'))
                    ->where('AcctStopTime' , 'LIKE', $data['date'] . '%', )->get()

16th November, 2017

imposition started a new conversation Form To Select Dates • 10 months ago

How do i create a form to select dates like From 02/01/2016 to 02/01/2017 And retrieve that data from my db? Can someone point me a tutorial ?

3rd November, 2017

imposition left a reply on Audit • 10 months ago

Something like this:

Route::post('/senhaf/search', ['middleware' => 'auth', 'audit', 'uses' => '[email protected]']);

imposition left a reply on Audit • 10 months ago

@mushood Bro, it still tracking every move my user make.

31st October, 2017

imposition left a reply on Audit • 10 months ago

@mushood I think what's making the whole thing work is this middleware:

<?php

namespace App\Http\Middleware;

use Closure;
use Jenssegers\Agent\Agent;
use App\Audit as Auditor;

class Audit
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {

        $agent = new Agent();


        if ( \Auth::check() ) {

            Auditor::create([
                'user_id'    => \Auth::user()->id,
                'method'     => $request->getMethod(),
                'path' => $request->getPathInfo(),
                'query'      => $request->getQueryString(),
                'userAgent' => $agent->getUserAgent(),
                'ip'        => \Request::ip(),
                'device' => $agent->device(),
                'platform' => $agent->platform(),
                'browser' => $agent->browser(),
                'isDesktop' => $agent->isDesktop(),
                'isMobile' => $agent->isMobile(),
                'isPhone' => $agent->isPhone(),
                'isTablet' => $agent->isTablet()
            ]);
        }

        return $next($request);
    }
}

What should i do to make it only work in specific routes? Like... I want it to only work in this 3 routes

Route::get('/senhaf', ['middleware' => 'auth', 'uses' => '[email protected]']);
Route::get('/senhaw', ['middleware' => 'auth', 'uses' => '[email protected]']);
Route::get('/senhaw/{rad}/edit', ['middleware' => 'auth', 'uses' => '[email protected]']);
Route::patch('/senhaf/{radius}', ['middleware' => 'auth', 'uses' => '[email protected]']);
Route::patch('/senhaw/{radius}', ['middleware' => 'auth', 'uses' => '[email protected]']);

30th October, 2017

imposition started a new conversation Audit • 10 months ago

Hi there! I made an Audit and it's working fine. But here is my problem. It's saving every single move my users make. I just want to save when they access an specific route For example I have the routes: /xxx /xxx1 /xxx2 /xxx3 I want my Audit only to make records about the /xxx3 url. Only when my user access /xxx3 then save into my DB

This is my model if it has any use:

use Illuminate\Database\Eloquent\Model;

class Audit extends Model
{

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'user_id', 'method', 'path', 'query', 'userAgent', 'ip', 'device' , 'platform', 'browser' , 'isDesktop', 'isMobile' , 'isPhone' , 'isTablet'
    ];


    public function user ()
    {
        return $this->belongsTo(User::class);
    }


    /**
     * Get online users
     *
     * @param int $min
     * @return \Illuminate\Database\Eloquent\Collection|static[]
     */
    public function online ($min = 3)
    {

        return $this->select('user_id')
                    ->where('audits.created_at', '>=', Carbon::now()->subMinutes($min)->toDateTimeString())
                    ->distinct('user_id')
                    ->with('user')
                    ->get()->map(function ($item) {
                        return $item->user;
                    });

    }
}

27th October, 2017

imposition left a reply on Which User Deleted What? • 10 months ago

@kfirba i have native auth I just want to know how to make logs of each users activity... Which tools were used and stuff like that.

26th October, 2017

imposition started a new conversation Which User Deleted What? • 10 months ago

Is possible to create a log that show me what each user deleted or edited ?

imposition left a reply on Select Different Table . • 10 months ago

@Snapey Found my problem... Was missing a } at the end of my model.

imposition left a reply on Select Different Table . • 10 months ago

@Snapey i know that but we use fiber because of the label of equips we use... fiberhome.

imposition left a reply on Select Different Table . • 10 months ago

@Snapey Why ?

imposition left a reply on Select Different Table . • 10 months ago

@Snapey Created this model:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use DB;


class PatchFiber extends Model
{
// ------------------ // -----------------//
// Conexão ao Database                   //
// ------------------//------------------//
    protected $connection = 'radiusfiber';

// ------------------ // -----------------//
// Tabela Utilizada no DB                //
// ------------------//------------------//
    protected $table  = 'radcheck';

// ------------------ // -----------------//
// Fillable com mass assignment           //
// ------------------//------------------//
    protected $guarded = [];

// ------------------ // -----------------//
// Timestamps desativados                //
// ------------------//------------------//
    public $timestamps = false;


And updated my method to:


    public function update(Request $request, PatchFiber $radius)
    {   
        $radius->update([
            'Value' => $request['Value']
            ]);
        return redirect('home');
    }

Also added use App\PatchFiber; to my controller

imposition left a reply on Select Different Table . • 10 months ago

@Snapey When i do that i get this error: ReflectionException Class App\PatchFiber does not exist

_>

imposition left a reply on Select Different Table . • 10 months ago

@Snapey I've created another model... But i can't figure out how to edit my update method to match my new model :c

imposition started a new conversation Select Different Table . • 10 months ago

I have this model:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use DB;

class RadiusFiber extends Model
{
// ------------------ // -----------------//
// Conexão ao Database                   //
// ------------------//------------------//
    protected $connection = 'radiusfiber';

// ------------------ // -----------------//
// Tabela Utilizada no DB                //
// ------------------//------------------//
    protected $table  = 'radreply';

// ------------------ // -----------------//
// Fillable com mass assignment           //
// ------------------//------------------//
    protected $guarded = [];

// ------------------ // -----------------//
// Timestamps desativados                //
// ------------------//------------------//
    public $timestamps = false;

// ------------------ // -----------------//
// Seleciona a conexão com DB             //
// ------------------//------------------//
    protected function searchIP($data = [])
    {
    
        
         $data = RadiusFiber::where('UserName' , 'LIKE', $data['search'] . '%')->get();
         return $data;
           }

  }

And this controller:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use DB;
use App\RadiusFiber;
use App\Form;

class RadiusController extends Controller
{


// ------------------ // -----------------//
// PAGINA INICIAL RADIUS                //
// ------------------//------------------//

    public function index()
    {
        $data = [];
        return view('radius.index', compact('data'));
    }


// ------------------ // -----------------//
// PAGINA DE EDIÇÃO RADIUS                //
// ------------------//------------------//

    public function edit(RadiusFiber $rad)
    {
        return view('radius.edit', compact('rad'));
    }

// ------------------ // -----------------//
// EDITAR DADOS RADIUS ----               //
// ------------------//------------------//
   

    public function update(Request $request, RadiusFiber $radius)
    {   
        $radius->update([
            'Value' => $request['Value']
            ]);
        return redirect('home');
    }

// ------------------ // -----------------//
// PROCURAR LOGINS                       //
// ------------------//------------------//

    public function search(Request $request)
     {   

         $logins = RadiusFiber::searchIP($request);

         foreach ($logins as $login) {
             if ($login->Attribute == 'Framed-IP-Address'){
                $data[] = array('UserName' => $login->UserName,
                            'ipAddress' => $login->Value,
                            'id' => $login->id
                        );
             }
         }
         
         return view('radius.index', compact('data'));
    }
   
// ------------------ // -----------------//
// DELETAR IP                             //
// ------------------//------------------//    
    public function DeleteConfirmation($userName)

    {

            return view ('radius.delete', compact('userName'));
       
        

    }

public function Destroy()

{
   
      
   try 
        {
   
            DB::transaction(function ()
                {

                $toDelete = request('delete');

                RadiusFiber::where('UserName', $toDelete )->delete();

                });

                return redirect('home');

        }  

    catch(\Exception $e)
        {
           
            return 'nao deu';

        }
   
}
}

I want this method:

// ------------------ // -----------------//
// EDITAR DADOS RADIUS ----               //
// ------------------//------------------//
   

    public function update(Request $request, RadiusFiber $radius)
    {   
        $radius->update([
            'Value' => $request['Value']
            ]);
        return redirect('home');
    }

To use a different table from that specified on my model

How to do that ?

24th October, 2017

imposition started a new conversation How To Change The Default Auth Forgot Pass Email That Is Sent? • 10 months ago

Can anyone point me for where i can change the email sent by native forgotpass?

https://prnt.sc/h1c7wv <- This one

20th October, 2017

imposition left a reply on Multiple DB Connections! • 11 months ago

@jlrdw created new model/controller One for each DB Solved my problem for now. My system is close to be done I just needed this one. So i did like this to wrap it up. And when i have some more time i'll finish this the right way

imposition left a reply on Delete From Database. • 11 months ago

@Corban I didn't mistake you I marked because it was really helpfull And it didn't work because of a mistake i've made before. You were really helpfull Thanks <3

imposition left a reply on Delete From Database Working But Not Deleting • 11 months ago

Found the error... apparently it only selects the connection for Search Not for Destroy.

imposition left a reply on Transaction • 11 months ago

imposition left a reply on Transaction • 11 months ago

@tykus No but i solved that already. Forgot to update the code... Did like this

public function Destroy()
{
   try 
        {
   
            DB::beginTransaction();

                $toDelete = request('delete');

                Radius::where('UserName', $toDelete )->delete();

            DB::commit();
                return redirect('home');

        }  

    catch(ValidationException $e)
        {
            DB::rollBack();
            return 'nao deu';

        }
   
}

imposition started a new conversation Delete From Database Working But Not Deleting • 11 months ago

Hi there! I have a method that delete stuff from my DB

public function Destroy()
{
   try 
        {
   
            DB::beginTransaction();

                $toDelete = request('delete');

                Radius::where('UserName', $toDelete )->delete();

            DB::commit();
                return redirect('home');

        }  

    catch(ValidationException $e)
        {
            DB::rollBack();
            return 'nao deu';

        }
   
}

Relax, this works fine... Focus on my real problem! If i change my connection to Local DB in my Model

// ------------------ // -----------------//
// SELECT DB CONNECT             //
// ------------------//------------------//
    protected function searchIP($data = [])
    {
    
        if ($data->connection == 'fiber')
        {
            $this->connection = 'radiusfiber'; ->>>>>>> THIS OVER HERE!
IF I CHANGE THIS TO 'mysql'
        }
        else
        {
            $this->connection = 'radiuswireless';
        }
        
         $data = Radius::where('UserName' , 'LIKE', $data['search'] . '%')->get();
         return $data;
    }

The rows are deleted from my DB.

When i change the connection back to 'radiusfiber' my method work just fine... I get 0 error messages BUT the rows aren't deleted from my DB

imposition left a reply on Transaction • 11 months ago

@tykus And if there are any usernames alike

tykus tykus2 tykus3 tykus4

etc

My delete method will delete all rows with the username tykus :)

imposition left a reply on Transaction • 11 months ago

@tykus because now i'm going to insert more querys I just want to know if i'm doing this right

imposition started a new conversation Transaction • 11 months ago

Can anyone tell me if i'm doing this right?

  public function Destroy()

    {
   
DB::beginTransaction();

    $toDelete = request('delete');

    Radius::where('UserName', $toDelete )->delete();

if ($toDelete){

    DB::commit();
    return redirect('home');

}   
else
{
            DB::rollBack();
            return 'nao deu';

}

imposition left a reply on Delete From Database. • 11 months ago

@Corban even with the right variables i couldn't make it work exactly... It was almost all copy and paste i just made some changes on my controller that i hadn't posted here before... There was a messed up variable that made it not work actually. But thanks for your help I marked your answer as the best one :)

19th October, 2017

imposition left a reply on Delete From Database. • 11 months ago

Made it like this web.php

// // ------------------ // -----------------//
// // DELETE REQUEST                          //
// // ------------------//------------------// 
Route::get('radius/destroy/{username}', '[email protected]');
Route::delete('/destroyradius', '[email protected]');

RadiusController.php

// ------------------ // -----------------//
// DELETAR IP                             //
// ------------------//------------------//    
    public function DeleteConfirmation($userName)

    {
        return view ('radius.delete', compact('userName'));

    }

    public function Destroy()

    {
   
    $toDelete = request('delete');

    Radius::where('UserName', $toDelete )->delete();

    return redirect('/');
   
    }

index view

        <td><a href="/radius/destroy/{{ $d['UserName'] }}" class="fa fa-trash" aria-hidden="true"></i></a></td>

delete view

    <form method="post" action="/destroyradius" class="">
        {{ csrf_field() }}
    {{ method_field('delete') }}
         <div class=""> 
        Are you sure you want to delete {{ $userName }} ?
     </div>
    <div class="">
        <input type="hidden" value="{{ $userName }}" name="delete">  
        <button class="" type="submit" >Confirm</button>
        <button class="" type="submit"onclick="window.history.go(-1)" >No, Wait!</button>
    </div>
        </form>

It works fine

imposition left a reply on Delete From Database. • 11 months ago

@Corban Does not work :/ ErrorException (E_ERROR) htmlspecialchars() expects parameter 1 to be string, array give Doesn't even know what i'm doin wrong :c

imposition left a reply on Delete From Database. • 11 months ago

@jontyjago Class 'Form' not found (View: /var/www/html/projeto/resources/views/radius/index.blade.php Got this error after adding that form to my view

@tisuchi

my table goes like this

[
                    'UserName' => trim($data->username),
                    'Attribute' => 'Framed-IP-Address',
                    'op' => '=',
                    'Value' => trim($data->ipv4)
                ],
                [
                    'UserName' => trim($data->username),
                    'Attribute' => 'Framed-MTU',
                    'op' => '=',
                    'Value' => '1492'
                ],
                [
                    'UserName' => trim($data->username),
                    'Attribute' => 'Service-Type',
                    'op' => '=',
                    'Value' => 'Framed-User'
                ],
                [
                    'UserName' => trim($data->username),
                    'Attribute' => 'Framed-Protocol',
                    'op' => '=',
                    'Value' => 'PPP'
                ],
                [
                    'UserName' => trim($data->username),
                    'Attribute' => 'Framed-Compression',
                    'op' => '=',
                    'Value' => 'Van-Jacobson-TCP-IP'
                ]

imposition left a reply on Delete From Database. • 11 months ago

@tisuchi I don't have a delete method... I don't know how to make one :c

18th October, 2017

imposition left a reply on Delete From Database. • 11 months ago

@bnazarov@abv.bg i have done that yet... But the delete part i can't figure that out by myself

imposition left a reply on Delete From Database. • 11 months ago

@tisuchi I have this Model

    protected function searchIP($data = [])
    {
    
        if ($data->connection == 'fiber')
        {
            $this->connection = 'radiusfiber';
        }
        else
        {
            $this->connection = 'radiuswireless';
        }
        
         $data = Radius::where('UserName' , 'LIKE', $data['search'] . '%')->get();
         return $data;
    }
// --

This controller

// ------------------ // -----------------//
// PROCURAR LOGINS                       //
// ------------------//------------------//

    public function search(Request $request)
     {   

         $logins = Radius::searchIP($request);

         foreach ($logins as $login) {
             if ($login->Attribute == 'Framed-IP-Address'){
                $data[] = array('UserName' => $login->UserName,
                            'ipAddress' => $login->Value);
             }
         }
         return view('radius.index', compact('data'));
    }

And this view

<div class="container">
    <div class="row">
        <div class="col-md-10 col-md-offset-1">
            <div class="panel panel-default">
                <div class="panel-heading">Consultar clientes com IP Fixo</div>
                <div class="panel-body">

                <form  method="POST" action="/radius/search">

                    <input type="hidden" name="_token" value="{{ csrf_token() }}">  
                     <div class="col-md-5">
                        <div class="form-group">
                            <input type="text" name="search" class="form-control" placeholder="Buscar Login"/>
                        </div>
                    </div>


                    <div class="col-md-5">
                    <div class="form-group">
                   
                    <select id="connection" name="connection" class="form-control">
                        <option value="fiber">Fibra</option>
                        <option value="wireless">Wireless</option>
                    </select>
                </div>

                            <button type="submit" class="btn btn-default btn-flat">Buscar</button>                          
                        </div>
                    </div>
                </form>
               <table class="table table-striped">                        
      
        <th>Login</th>
        <th>Ip</th>
        <th>Delete</th>
        @foreach($data as $d)
        <tr>
        <td> {{ $d['UserName'] }}</td>                  
        <td>{{ $d['ipAddress'] }}</td>
        <td><a href="#" onclick="return confirm('Deseja realmente excluir esse item?');"><i class="fa fa-trash" aria-hidden="true"></i></a></td>
        </tr>
        @endforeach 
        
        </table>

I want that clickable item on the table 3rd row to delete five rows with the same username of my db

imposition started a new conversation Delete From Database. • 11 months ago

I want to delete 5 lines from my database using a button The 5 lines have the same username How do i do that ?

13th October, 2017

imposition left a reply on @if Auth::user()->type • 11 months ago

@Snapey Thank you very much!

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.