ottaviane

ottaviane

Member Since 6 Months Ago

Experience Points 580
Experience Level 1

4,420 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed 1
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

09 Jun
2 months ago

ottaviane left a reply on Routing Not Working

Thank you. now it works!!!! thank you very mutch.

08 Jun
2 months ago

ottaviane left a reply on Routing Not Working

hi all. I have this route:

Route::group(['namespace' => 'Magazzino', 'prefix' => 'Magazzini'], function()
{
  Route::resource('/', 'MagazziniController');
});

infact php artisan route:list gives

|        | POST      | Magazzini                          | store               | App\Http\Controllers\Magazzino\[email protected]               | web                          |
|        | GET|HEAD  | Magazzini                          | index               | App\Http\Controllers\Magazzino\[email protected]               | web                          |
|        | GET|HEAD  | Magazzini/create                   | create              | App\Http\Controllers\Magazzino\[email protected]              | web                          |
|        | DELETE    | Magazzini/{}                       | destroy             | App\Http\Controllers\Magazzino\[email protected]             | web                          |
|        | PUT|PATCH | Magazzini/{}                       | update              | App\Http\Controllers\Magazzino\[email protected]              | web                          |
|        | GET|HEAD  | Magazzini/{}                       | show                | App\Http\Controllers\Magazzino\[email protected]                | web                          |
|        | GET|HEAD  | Magazzini/{}/edit                  | edit                | App\Http\Controllers\Magazzino\[email protected]                | web                          |

and routing to index() and to create() works very good. But when I call mysite/Magazzini/1 for example, routing don't works. I made this form:

  <form id='deleteform' class="" action="/Magazzini/{{ $mag->id }}" method="POST" enctype="multipart/form-data">
      @method("DELETE")
      @csrf
      
    </form>

and when I submit it I receive a 404 error end the funtion

public function destroy($id)
    {
        dd($id);
    }

of my controller isn't called. I'm not able even call update and show methods of my controller. What appened? thanks. bye.

ottaviane started a new conversation Routing Not Working

routing not working

23 May
2 months ago

ottaviane left a reply on Not Display Properly Bootstrap Div With Laravel App

I think it's a HTML error. Have you debugged Page Source? Normally, to find those mistakes, I use 'inspect element' function, or Page Source in my browser. Another thing: the 'link' tag must have the {{ asset ....}} in href dirctive

ottaviane left a reply on Change Database Dynamically

googling I found it:

//get old dbname
$oldDbName = env("DB_DATABASE");


$env = new DotenvEditor();
$env->changeEnv([
   'DB_HOST' => $request['hostname'],
   'DB_DATABASE' => $request['dbname'],
   'DB_USERNAME' => $request['username'],
   'DB_PASSWORD' => $request['dbpassword'],
]);

DB::disconnect(env("DB_CONNECTION"));

Config::set('database.connections.' . env("DB_CONNECTION"), array(
        'driver'    => 'mysql', //or $request['driver'],
        'host'      => $request['hostname'],
        'database'  => $request['dbname'],
        'username'  => $request['username'],
        'password'  => $request['dbpassword'],
        'charset'   => 'utf8',
        'collation' => 'utf8_general_ci',
        'prefix'    => '',
));

//Trying reconnect database
try {
        DB::connection()->getPdo();
    } catch (\Exception $e) {
        //revert old db if any error
        DB::disconnect(env("DB_CONNECTION"));
        Config::set('database.connections.' . env("DB_CONNECTION") .'.database', $oldDbName );
    }

I don't know if it works, but it seems to be what you need... I hope.

ottaviane left a reply on Change Database Dynamically

@CMDOBUENO - I think cronix is right. I add: a multidatabase approach, in some contexts, can also be much more elegant and orderly.

07 May
3 months ago

ottaviane left a reply on Quering A Ldapserver And Synchronize Laravel Database

@MARTINBEAN - thank you for your precious help. the real reason is that my laravel must authenticate 90% of users entirely managed by ldap, to which server I do not have administrative access, and 10% of users managed entirely by me locally. The two things must be merged invisibly. Furthermore, the authentication on ldap is very slow for technical reasons that I cannot solve (insurmountable administrative issues). In doing so, I speeded up the authentication because, in fact, after the first time the user has logged in, it is registered locally and for the future it is logged in locally much faster. If the password should change, the system will automatically ask ldap and, if the different credentials are valid for ldap, the local record is updated ... and so on.

In turn local users who do not have to be created on ldap, being valid already at the first stage, do not create any problem.

I have also already created my own provider that queries ldap and works great

I hope I was clear. thank you so much

04 May
3 months ago

ottaviane left a reply on Using Admin Middleware In Some Only Resource Routing

@SERGIU17 - perfect! thank you very very mutch.

ottaviane started a new conversation Using Admin Middleware In Some Only Resource Routing

Hi, I have this middleware:

class Admin
{  
     public function handle($request, Closure $next)
     {
       if(auth()->user()->isAdmin !== null)
       {
         if (auth()->user()->isAdmin == 1) {
             return $next($request);
         }
       }
       return redirect('/')->with('error', 'You have not admin access.');
     }
}

and I have this routes in web.php

Route::get('/raccolte/{id}/switch','[email protected]')->middleware('admin');
Route::get('/raccolte/{id}/{id2}/scambia','[email protected]')->middleware('admin');
Route::resource('raccolte','RaccolteController');

and with artisan route:list I have

 GET|HEAD  | raccolte                   | raccolte.index  | App\Http\Controllers\[email protected]   | web,auth       |
 POST      | raccolte                   | raccolte.store  | App\Http\Controllers\[email protected]   | web,auth       |
 GET|HEAD  | raccolte/create            | raccolte.create | App\Http\Controllers\[email protected]  | web,auth       |
 GET|HEAD  | raccolte/{id}/switch       |                 | App\Http\Controllers\[email protected]  | web,admin,auth |
 GET|HEAD  | raccolte/{id}/{id2}/scambia|                 | App\Http\Controllers\[email protected] | web,admin,auth |
 GET|HEAD  | raccolte/{raccolte}        | raccolte.show   | App\Http\Controllers\[email protected]    | web,auth       |
 PUT|PATCH | raccolte/{raccolte}        | raccolte.update | App\Http\Controllers\[email protected]  | web,auth       |
 DELETE    | raccolte/{raccolte}        | raccolte.destroy| App\Http\Controllers\[email protected] | web,auth       |
 GET|HEAD  | raccolte/{raccolte}/edit   | raccolte.edit   | App\Http\Controllers\[email protected]    | web,auth       |

I'd like to protect with middleware only a part of resource route:

|POST    |raccolte       |...store |[email protected] |web,auth|
|GET|HEAD|raccolte/create|...create|[email protected]|web,auth|

how can I do it in the best way so that 'php artisan route:list' shows me those filters? thanks, bye.

ottaviane left a reply on Quering A Ldapserver And Synchronize Laravel Database

@SNAPEY - Hi Snapey. I resolved. I hope the solution described at the top of this discussion can help somebody. Thanks for your valuable help.

ottaviane left a reply on Quering A Ldapserver And Synchronize Laravel Database

@MARTINBEAN - at the top I explained and solved. thank you

ottaviane left a reply on Quering A Ldapserver And Synchronize Laravel Database

finally I resolved my problem:

protected function attemptLogin(Request $request)
    {
      if($this->guard()->attempt($this->credentials($request), $request->filled('remember'))) //if user is valid in Laravel
      {
        return true;
      }
      else
      {
        if(my_ldap_verify($request)) //if user is valid in ldap server
        {
          $mycredentials['email']=$request['email'];
          $mycredentials['password']=Hash::make($request['password']);
          $mycredentials['name']=$request['email'];
          $user = User::updateOrCreate($mycredentials); //add new user with credentials to users table in my database if not exists or update it if password changed
          $this->guard()->attempt($this->credentials($request), $request->filled('remember')); //relogin

          return true;
        }
        else return false;
      }
    }

thanks all

03 May
3 months ago

ottaviane left a reply on Quering A Ldapserver And Synchronize Laravel Database

@SNAPEY - I made it:

  protected function attemptLogin(Request $request)
    {

      if($this->guard()->attempt($this->credentials($request), $request->filled('remember'))) //if user is valid in Laravel
      {
          return true;
      }
      else
      {
        if(my_fake_ldap_verify($request)) //if user is valid in ldap server
        {
          $mycredentials['email']=$request['email'];
          $mycredentials['pass']=$request['password'];
          $request['name']=$request['email'];
          //dd($request);
          $user = User::updateOrCreate(request(['name','email','password'])); //add new user with credentials to users table in my database if not exists or update it if password changed
          //  dd($user);
          //dd(compact('mycredentials'));
          return Redirect::route('login')->with('mycredentials',$mycredentials);
          //2 -  resend same login request recalling the form login.blade.php
        }
        else return false;
      }
    }

It works fine, and adds new records with the same user abilited bay ldap. I need so to encrypt password in new records and to modify login.blade.php with a script who make autologin. What do you mean?

ottaviane left a reply on Quering A Ldapserver And Synchronize Laravel Database

@SNAPEY - Yes, the objective is to auto register users that are known in the directory. I was thinking of taking the password, which is certainly valid for ldap, from the request ... mmhhh ... I think it may be a good solution. And, it is important, users should not notice this, so they don't go in confusion.

ottaviane left a reply on Quering A Ldapserver And Synchronize Laravel Database

@SNAPEY - I thought I'd do this, correct me if I'm wrong please:

// in my LoginController.php...
protected function attemptLogin(Request $request)
    {

      if($this->guard()->attempt($this->credentials($request), $request->filled('remember')))
      {
          return true;
      }
      else
      {
        if(myldapverify($request))
        {
          1 -  with DB fake add new user with credentials to users table in my database if not exists or update it if password changed
          2 -  resend same login request recalling the form login.blade.php
        }
        else return false;
      }
    }

What do you think about it?

ottaviane left a reply on Quering A Ldapserver And Synchronize Laravel Database

@SNAPEY - I'm sorry but sometimes I look stupid! You're right! I have included the library and it works. Just what I needed. Let me see: you did an overriding of a method, right?

ottaviane left a reply on Quering A Ldapserver And Synchronize Laravel Database

@SNAPEY - Thanks and good morning.

it would be better to log in to laravel first, but if I solve it, the opposite is also fine.

In LoginController.php I added this:

protected function attemptLogin(Request $request)
    {
        return $this->guard()->attempt(
            $this->credentials($request), $request->filled('remember')
        );
    }

but I receive an error:

 Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_RECOVERABLE_ERROR)
Argument 1 passed to App\Http\Controllers\Auth\LoginController::attemptLogin() must be an instance of App\Http\Controllers\Auth\Request, instance of Illuminate\Http\Request given, called in /home/ottaviane/Sviluppo/vvfsr/vendor/laravel/framework/src/Illuminate/Foundation/Auth/AuthenticatesUsers.php on line 44

bye.

02 May
3 months ago

ottaviane left a reply on Quering A Ldapserver And Synchronize Laravel Database

@DAVIDPETROV - I tried to override the function like that

...
class LoginController extends Controller
{
...
    public function __construct()
    {
        $this->middleware('guest')->except('logout');
    }
    protected function sendFailedLoginResponse(Request $request)
    {
            return view('myooop.php');
    }
}

But I receive this error:

Argument 1 passed to App\Http\Controllers\Auth\LoginController::sendFailedLoginResponse() must be an instance of App\Http\Controllers\Auth\AuthRequest, instance of Illuminate\Http\Request given, called in /home/ottaviane/Sviluppo/vvfsr/vendor/laravel/framework/src/Illuminate/Foundation/Auth/AuthenticatesUsers.php on line 53

ottaviane left a reply on Quering A Ldapserver And Synchronize Laravel Database

@MARTINBEAN - I need to query an ldap server if the user is not recognized by Laravel. If the ldap server returns the ok (and here there is no problem) then the user must be considered logged in.

ottaviane left a reply on Quering A Ldapserver And Synchronize Laravel Database

I made in login.blade.php file

@error('email')
  <script type="text/javascript">
     window.location = "/myerrorpage.php";
  </script>         
@enderror

But is there any better way to do it?

01 May
3 months ago

ottaviane started a new conversation Quering A Ldapserver And Synchronize Laravel Database

old title: intercepting laravel login error.

Hi to all. I updated the title because the problem eventually widened. if someone has the same problem as me, they can use this code that I developed thanks to the help of this forum, but in particular thanks to Snapey. I summarize the problem-solution:

  • in an already functioning network where authentication takes place on an existing ldap server, I have to insert a new web server (laravel) using the same accounts already present on the said server;
  • I'd like to use login/service already working in Laravel;
  • The best solution is:
    1. Laravel show login view;
    2. User go with his credentials
    3. Laravel query its user table, if is present login is ok
    4. if login is'nt ok, laravel query ldap. If ldap fails laravel show error
    5. if ldap replay that user is valid, Laravel add new user-record in database and attempt login of new user.

All this I made in LoginController :

protected function attemptLogin(Request $request)
    {
      if($this->guard()->attempt($this->credentials($request), $request->filled('remember'))) //if user is valid in Laravel
      {
        return true;
      }
      else
      {
        if(my_ldap_verify($request)) //if user is valid in ldap server
        {
          $mycredentials['email']=$request['email'];
          $mycredentials['password']=Hash::make($request['password']);
          $mycredentials['name']=$request['email'];
          $user = User::updateOrCreate($mycredentials); //add new user with credentials to users table in my database if not exists or update it if password changed
          $this->guard()->attempt($this->credentials($request), $request->filled('remember')); //relogin

          return true;
        }
        else return false;
      }
    }

Thanks all very much.

24 Apr
3 months ago

ottaviane started a new conversation Difference Betwen Static & Dinamically Instantiate Models

is there anyone who knows how to read a documentation with examples on dinamically instatiate models? What are methods? thanks. bye.

ottaviane started a new conversation Saving Record " ErrorException (E_NOTICE) Array To String Conversion"

Hi all. I have to save record in a table but I receive this error message: " ErrorException (E_NOTICE) Array to string conversion"

This is code:

public function store(Request $request)
    {
        //aggiungi un record
        $id_tab=request(['id_tab']);
        $id_canto=$request['canti'];
        $tab=new SpartInRacc;//new instance of my model
        $tab->setTable($id_tab);
        $tab->id_canto=$id_canto;
        $tab->save();        
        return redirect('/spartinracc');
    }

and dd($tab); outs

    SpartInRacc {#244 ▼
  #table: array:1 [▼
    "id_tab" => "13-Natale"
  ]
  #fillable: array:1 [▼
    0 => "id_canto"
  ]
  #connection: null
  #primaryKey: "id"
  #keyType: "int"
  +incrementing: true
  #with: []
  #withCount: []
  #perPage: 15
  +exists: false
  +wasRecentlyCreated: false
  #attributes: array:1 [▼
    "id_canto" => "22"
  ]
  #original: []
  #changes: []
  #casts: []
  #dates: []
  #dateFormat: null
  #appends: []
  #dispatchesEvents: []
  #observables: []
  #relations: []
  #touches: []
  +timestamps: true
  #hidden: []
  #visible: []
  #guarded: array:1 [▼
    0 => "*"
  ]
}

dd($id_canto); outs

"22"

where is the mistake? Bye