afonte15

Experience

9,790

0 Best Reply Awards

  • Member Since 2 Years Ago
  • 105 Lessons Completed
  • 1 Favorite

12th October, 2017

afonte15 left a reply on Dropping Foreign Keys • 6 days ago

All Models listed above... I missed some of the notation so they all did not save. I also tried adding id to the protected fillable in the models but that did not work either.

But just in case here is the inventory model

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Inventory extends Model
{
    /**
     *Fillable fields for Inventory
     *
     * @var array
     */
    protected $fillable = [
        'employee_id',
        'location_id',
        'device_id'
    ];

}

afonte15 left a reply on Dropping Foreign Keys • 6 days ago

@Devon I do have models set up and prior to making the change to multiple migrations I had only a Inventories.php and data did sumbit to the database. Now I have 5 models which are listed below. I am still getting the error I pasted above.

Employee Model

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Employee extends Model
{
    protected $fillable = [
        'lastName',
        'firstName',
        'department'
    ];
}

Location Model

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Employee extends Model
{
    protected $fillable = [
        'lastName',
        'firstName',
        'department'
    ];
}

device model


<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Device extends Model
{
    protected $fillable = [
        'manufacturer' ,
        'device',
        'model',
        'tag',
        'macAddress'
        ];
}

Status Model

afonte15 left a reply on Dropping Foreign Keys • 6 days ago

@Dunsti I was able to get the database to drop and migrate. My issue is data does not submit to the database and I get the above error.

afonte15 left a reply on Dropping Foreign Keys • 1 week ago

This is my InventoriesController.php

<?php
namespace  App\Http\Controllers;
use Illuminate\Http\Request;
use DB;
use App\Inventory;
use App\Http\Requests\InventoryRequest;
use App\User;
class InventoriesController extends Controller
{
    public function __construct()
    {
        $this->middleware('auth');  //does not allow users to login, redirects back to login when using LDAP credentials
    }
    public function index(Request $request)
    {
        $location = $request->input("building");
        if ($location != null) {
            $inventories = Inventory::where('building', $location)->get();
        }  else {
            $inventories = Inventory::all();
        }
        return view('computers.index', compact('inventories'));
    }
    public function show($inventories)
    {
        $inventories = Inventory::findOrFail($inventories);
        return view::make('computers.show')
            ->with('inventory', $inventories);
    }
    public function create(){
        //flash('Hello World', 'This is the message');
        $user = User::current();
        return view('computers.create',['user' => $user]);// add back in parenthesis
    }
    /**
     * Store a newly created resource in storage.
     *
     * @param  inventory  $request
     * @return Response
     *
     */
    public function store(InventoryRequest $request)
    {
        Inventory::create($request->all());
        flash('Success!', 'Inventory Successfully Updated!');
//
//        return redirect()->back();  //temporary
        return back();
    }
    public function edit($inventories)
    {
        $inventories = Inventory::findOrFail($inventories);
        return view('computers.edit', compact('inventories'));
    }
    public function update(InventoryRequest $request, Inventory $inventories){
        $inventories->update($request->all());
        flash('Success!', 'Inventory Successfully Updated!');
        return back();
    }
    public function search()
    {
        $search = \Request::get('q'); //<-- we use global request to get the param of URI
//            $search = Input::get('search');
        $inventories = Inventory::where('lastName','LIKE','%'.$search.'%')
            -> orwhere('firstName', 'LIKE','%'.$search.'%' )
            -> orwhere('department', 'LIKE','%'.$search.'%' )
            -> orwhere('building', 'LIKE','%'.$search.'%' )
            -> orwhere('room', 'LIKE','%'.$search.'%' )
            -> orwhere('manufacturer', 'LIKE','%'.$search.'%' )
            -> orwhere('device', 'LIKE','%'.$search.'%' )
            -> orwhere('model', 'LIKE','%'.$search.'%' )
            -> orwhere('tag', 'LIKE','%'.$search.'%' )
            -> orwhere('macAddress', 'LIKE','%'.$search.'%' )
            -> orwhere('status', 'LIKE','%'.$search.'%' )
            -> orwhere('notes', 'LIKE','%'.$search.'%' )
            ->get();
        return view('computers.search',compact('inventories'));
    }
}

11th October, 2017

afonte15 left a reply on Dropping Foreign Keys • 1 week ago

@Devon I actually did make those changes and when I did I was able to drop and add (php artisan migrate:reset and php artisan migrate) the tables without issues but I still get the error above regarding the foreign keys. Below is the current and updated migration codes and still receiving the error above.

employees table

<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateEmployeesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('employees', function (Blueprint $table) {
            $table->increments('id');
            $table->string('lastName', 25);
            $table->string('firstName', 25);
            $table->string('department', 35);
            $table->timestamps();
            //
        });
    }
    
    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('employees');
}
}

locations table

<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateLocationsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('locations', function (Blueprint $table) {
            $table->increments('id');
            $table->string('building', 25);
            $table->string('room',25);

        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('locations');
    }
}


devices table

afonte15 left a reply on Dropping Foreign Keys • 1 week ago

I tired it 2 ways and it still fails.

Both migrations listed below is the inventories_table.

<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateInventoriesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('inventories', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('employee_id')->unsigned();
            $table->integer('location_id')->unsigned();
            $table->integer('device_id')->unsigned();
            $table->foreign('employee_id')->references('id')->on('employees')->onDelete('cascade');
            $table->foreign('location_id')->references('id')->on('locations')->onDelete('cascade');
            $table->foreign('device_id')->references('id')->on('devices')->onDelete('cascade');
            $table->timestamps();
        });
    }
    
    /**
     * Reverse the migrations.
     *
     * @return void
     */
    
    public function down()
    
    {
    
        Schema::table('inventories', function(Blueprint $table)
        {
            $table->dropForeign(['employee_id_foreign']);
            $table->dropColumn('employee_id');
            $table->dropForeign(['location_id']);
            $table->dropColumn('location_id');
            $table->dropForeign(['device_id']);
            $table->dropColumn('device_id');
    
    
    
        });
            Schema::drop('inventories');
    }
}



?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateInventoriesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('inventories', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('employee_id')->unsigned();
            $table->integer('location_id')->unsigned();
            $table->integer('device_id')->unsigned();
            $table->foreign('employee_id')->references('id')->on('employees')->onDelete('cascade');
            $table->foreign('location_id')->references('id')->on('locations')->onDelete('cascade');
            $table->foreign('device_id')->references('id')->on('devices')->onDelete('cascade');
            $table->timestamps();
        });
    }
    
    /**
     * Reverse the migrations.
     *
     * @return void
     */
    
    public function down()
    
    {
    
        Schema::table('inventories', function(Blueprint $table)
        {
            $table->dropForeign(['inventories_employee_id_foreign']);
            $table->dropColumn('employee_id');
            $table->dropForeign(['inventories_location_id']);
            $table->dropColumn('inventories_location_id');
            $table->dropForeign(['inventories_device_id']);
            $table->dropColumn('device_id');
    
    
    
        });
            Schema::drop('inventories');
    }
}

The exact Errors I recieve is listed below.


PDOException in Connection.php line 457:
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`lawInventory`.`inventories`, CONSTRAINT `inventories_employee_id_foreign` FOREIGN KEY (`employee_id`) REFERENCES `employees` (`id`) ON DELETE CASCADE)
in Connection.php line 457
at PDOStatement->execute(array('2017-10-11 19:33:40', '2017-10-11 19:33:40')) in Connection.php line 457
at Connection->Illuminate\Database\{closure}(object(MySqlConnection), 'insert into `inventories` (`updated_at`, `created_at`) values (?, ?)', array('2017-10-11 19:33:40', '2017-10-11 19:33:40')) in Connection.php line 722
at Connection->runQueryCallback('insert into `inventories` (`updated_at`, `created_at`) values (?, ?)', array('2017-10-11 19:33:40', '2017-10-11 19:33:40'), object(Closure)) in Connection.php line 685
at Connection->run('insert into `inventories` (`updated_at`, `created_at`) values (?, ?)', array('2017-10-11 19:33:40', '2017-10-11 19:33:40'), object(Closure)) in Connection.php line 458
at Connection->statement('insert into `inventories` (`updated_at`, `created_at`) values (?, ?)', array('2017-10-11 19:33:40', '2017-10-11 19:33:40')) in Connection.php line 414
at Connection->insert('insert into `inventories` (`updated_at`, `created_at`) values (?, ?)', array('2017-10-11 19:33:40', '2017-10-11 19:33:40')) in Processor.php line 32
at Processor->processInsertGetId(object(Builder), 'insert into `inventories` (`updated_at`, `created_at`) values (?, ?)', array('2017-10-11 19:33:40', '2017-10-11 19:33:40'), 'id') in Builder.php line 2107
at Builder->insertGetId(array('2017-10-11 19:33:40', '2017-10-11 19:33:40'), 'id')
at call_user_func_array(array(object(Builder), 'insertGetId'), array(array('updated_at' => '2017-10-11 19:33:40', 'created_at' => '2017-10-11 19:33:40'), 'id')) in Builder.php line 1423
at Builder->__call('insertGetId', array(array('updated_at' => '2017-10-11 19:33:40', 'created_at' => '2017-10-11 19:33:40'), 'id')) in Model.php line 1628
at Model->insertAndSetId(object(Builder), array('updated_at' => '2017-10-11 19:33:40', 'created_at' => '2017-10-11 19:33:40')) in Model.php line 1597
at Model->performInsert(object(Builder), array()) in Model.php line 1488
at Model->save() in Model.php line 574
at Model::create(array('_token' => 'rDoLcbyfisd8UJWBySWtuODGbdv4zYRun4wRjNj0', 'lastName' => 'Fonteboa', 'firstName' => 'Angela', 'department' => 'Helpdesk', 'building' => 'VH', 'room' => '211', 'manufacturer' => 'Dell', 'device' => 'desktop', 'model' => 'Optiplex 9010', 'tag' => '123456', 'macAddress' => '1q2w3e4r5t6y', 'status' => 'active', 'notes' => 'No Notes Needed')) in InventoriesController.php line 51
at InventoriesController->store(object(InventoryRequest))
at call_user_func_array(array(object(InventoriesController), 'store'), array(object(InventoryRequest))) in Controller.php line 80
at Controller->callAction('store', array(object(InventoryRequest))) in ControllerDispatcher.php line 146
at ControllerDispatcher->call(object(InventoriesController), object(Route), 'store') in ControllerDispatcher.php line 94
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 102
at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 96
at ControllerDispatcher->callWithinStack(object(InventoriesController), object(Route), object(Request), 'store') in ControllerDispatcher.php line 54
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\InventoriesController', 'store') in Route.php line 174
at Route->runController(object(Request)) in Route.php line 140
at Route->run(object(Request)) in Router.php line 724
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in VerifyCsrfToken.php line 64
at VerifyCsrfToken->handle(object(Request), object(Closure))
at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in StartSession.php line 64
at StartSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))
at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure))
at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 102
at Pipeline->then(object(Closure)) in Router.php line 726
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 699
at Router->dispatchToRoute(object(Request)) in Router.php line 675
at Router->dispatch(object(Request)) in Kernel.php line 246
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 102
at Pipeline->then(object(Closure)) in Kernel.php line 132
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 99
at Kernel->handle(object(Request)) in index.php line 53



QueryException in Connection.php line 729:
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`lawInventory`.`inventories`, CONSTRAINT `inventories_employee_id_foreign` FOREIGN KEY (`employee_id`) REFERENCES `employees` (`id`) ON DELETE CASCADE) (SQL: insert into `inventories` (`updated_at`, `created_at`) values (2017-10-11 19:33:40, 2017-10-11 19:33:40))
in Connection.php line 729
at Connection->runQueryCallback('insert into `inventories` (`updated_at`, `created_at`) values (?, ?)', array('2017-10-11 19:33:40', '2017-10-11 19:33:40'), object(Closure)) in Connection.php line 685
at Connection->run('insert into `inventories` (`updated_at`, `created_at`) values (?, ?)', array('2017-10-11 19:33:40', '2017-10-11 19:33:40'), object(Closure)) in Connection.php line 458
at Connection->statement('insert into `inventories` (`updated_at`, `created_at`) values (?, ?)', array('2017-10-11 19:33:40', '2017-10-11 19:33:40')) in Connection.php line 414
at Connection->insert('insert into `inventories` (`updated_at`, `created_at`) values (?, ?)', array('2017-10-11 19:33:40', '2017-10-11 19:33:40')) in Processor.php line 32
at Processor->processInsertGetId(object(Builder), 'insert into `inventories` (`updated_at`, `created_at`) values (?, ?)', array('2017-10-11 19:33:40', '2017-10-11 19:33:40'), 'id') in Builder.php line 2107
at Builder->insertGetId(array('2017-10-11 19:33:40', '2017-10-11 19:33:40'), 'id')
at call_user_func_array(array(object(Builder), 'insertGetId'), array(array('updated_at' => '2017-10-11 19:33:40', 'created_at' => '2017-10-11 19:33:40'), 'id')) in Builder.php line 1423
at Builder->__call('insertGetId', array(array('updated_at' => '2017-10-11 19:33:40', 'created_at' => '2017-10-11 19:33:40'), 'id')) in Model.php line 1628
at Model->insertAndSetId(object(Builder), array('updated_at' => '2017-10-11 19:33:40', 'created_at' => '2017-10-11 19:33:40')) in Model.php line 1597
at Model->performInsert(object(Builder), array()) in Model.php line 1488
at Model->save() in Model.php line 574
at Model::create(array('_token' => 'rDoLcbyfisd8UJWBySWtuODGbdv4zYRun4wRjNj0', 'lastName' => 'Fonteboa', 'firstName' => 'Angela', 'department' => 'Helpdesk', 'building' => 'VH', 'room' => '211', 'manufacturer' => 'Dell', 'device' => 'desktop', 'model' => 'Optiplex 9010', 'tag' => '123456', 'macAddress' => '1q2w3e4r5t6y', 'status' => 'active', 'notes' => 'No Notes Needed')) in InventoriesController.php line 51
at InventoriesController->store(object(InventoryRequest))
at call_user_func_array(array(object(InventoriesController), 'store'), array(object(InventoryRequest))) in Controller.php line 80
at Controller->callAction('store', array(object(InventoryRequest))) in ControllerDispatcher.php line 146
at ControllerDispatcher->call(object(InventoriesController), object(Route), 'store') in ControllerDispatcher.php line 94
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 102
at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 96
at ControllerDispatcher->callWithinStack(object(InventoriesController), object(Route), object(Request), 'store') in ControllerDispatcher.php line 54
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\InventoriesController', 'store') in Route.php line 174
at Route->runController(object(Request)) in Route.php line 140
at Route->run(object(Request)) in Router.php line 724
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in VerifyCsrfToken.php line 64
at VerifyCsrfToken->handle(object(Request), object(Closure))
at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in StartSession.php line 64
at StartSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))
at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure))
at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 102
at Pipeline->then(object(Closure)) in Router.php line 726
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 699
at Router->dispatchToRoute(object(Request)) in Router.php line 675
at Router->dispatch(object(Request)) in Kernel.php line 246
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 102
at Pipeline->then(object(Closure)) in Kernel.php line 132
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 99
at Kernel->handle(object(Request)) in index.php line 53

afonte15 left a reply on Let's Build A Forum Series - Handler.php • 1 week ago

Yes, I posted above how I had the code written incorrectly!

@sutherland thank you again!

On another note if you have time to take a look at this thread....

https://laracasts.com/discuss/channels/eloquent/dropping-foreign-keys

afonte15 left a reply on Let's Build A Forum Series - Handler.php • 1 week ago

@sutherland I found my mistake! Thank you for your help and your patience...

The mistake was on my ThreadTest.php

 public function  setUp()
    {
        parent::setUp();
        
        $this->thread = factory('App\Thread')->create();

//I was missing the ->create(); from deleting and adding things on other pages when I was trying to figure out what was wrong which originally was the post method on my routes that I forgot to add that line back correctly.

    }

afonte15 left a reply on Let's Build A Forum Series - Handler.php • 1 week ago

It is there.... I even copied and pasted the code to make sure

thread.php

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;


class Thread extends Model
{
    /**
     * Don't auto-apply mass assignment protection.
     *
     * @var array
     */

    protected $guarded = [];
    /**
     * Get a string path for the thread.
     *
     * @return string
     */

    public function path()
    {
        return '/threads/' . $this->id;
    }

    /**
     * A thread may have many replies.
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */

    public function replies()
    {
        return $this->hasMany(Reply::class);
    }

    /**
     * A thread belongs to a creator.
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo

     */

    public function creator()
    {
        return $this->belongsTo(User::class, 'user_id');
    }

    /**
     * Add a reply to the thread.
     *
     * @param $reply
     */

    public function addReply($reply)
    {
        $this->replies()->create($reply);
    }
}

afonte15 left a reply on Let's Build A Forum Series - Handler.php • 1 week ago

Thank you @sutherland you are correct I was writting that incorrectly!

Now I receive this error when I run phpunit. I have copied and pasted from Jeff's github to my code. I am not sure why it is not recognizing addReply as a method.

[email protected]:~/Code/forum$ phpunit --filter ThreadTest
PHPUnit 6.4.1 by Sebastian Bergmann and contributors.

EEE                                                                 3 / 3 (100%)

Time: 622 ms, Memory: 8.00MB

There were 3 errors:

1) Tests\Unit\ThreadTest::a_thread_has_replies
ErrorException: Undefined property: Illuminate\Database\Eloquent\FactoryBuilder::$replies

/home/vagrant/Code/forum/tests/Unit/ThreadTest.php:28

2) Tests\Unit\ThreadTest::a_thread_has_a_creator
ErrorException: Undefined property: Illuminate\Database\Eloquent\FactoryBuilder::$creator

/home/vagrant/Code/forum/tests/Unit/ThreadTest.php:35

3) Tests\Unit\ThreadTest::a_thread_can_add_a_reply
BadMethodCallException: Method addReply does not exist.

/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Support/Traits/Macroable.php:97
/home/vagrant/Code/forum/tests/Unit/ThreadTest.php:41

ERRORS!
Tests: 3, Assertions: 0, Errors: 3.

afonte15 left a reply on Let's Build A Forum Series - Handler.php • 1 week ago

That is my Route for my Replies Controller just as Jeff has it. Unless I am making a typo error somewhere I am not sure what is wrong with my code.

Route::get('/threads/{thread}/replies', '[email protected]');

<?php

namespace App\Http\Controllers;

use App\Thread;
use Illuminate\Http\Request;

class RepliesController extends Controller
{
    public function __construct()
    {
        $this->middleware('auth');
    }
    
    public function store(Thread $thread)
    {
        $thread->addReply([
            'body' => request('body'),
            'user_id' => auth()->id()
        ]);
        
         return back();
    }
}

afonte15 started a new conversation Let's Build A Forum Series - Handler.php • 1 week ago

Hi,

I am currently going though the "Let's Build a Forum" but I am having trouble with the code from episode 4. When I run the phpunit test I get the error below.

I made the change just as Jeff did on Handler.php. Any help would be helpful as I cannot continue working on the project and would like to. I am currently using Laravel 5.5.


1) Tests\Feature\ParticipateInForumTest::an_authenticated_user_may_participate_in_forum_threads
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException: 

/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php:255
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php:242
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php:176
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Routing/Router.php:599
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Routing/Router.php:588
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Routing/Router.php:577
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:176
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:30
/home/vagrant/Code/forum/vendor/fideloper/proxy/src/TrustProxies.php:56
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:30
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:30
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php:27
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php:46
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:102
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:151
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:116
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php:294
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php:144
/home/vagrant/Code/forum/tests/Feature/ParticipateInForumTest.php:34


There was 1 failure:

1) Tests\Feature\ParticipateInForumTest::unauthenticated_users_may_not_add_replies
Failed asserting that exception of type "Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException" matches expected exception "Illuminate\Auth\AuthenticationException". Message was: "" at
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php:255
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php:242
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php:176
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Routing/Router.php:599
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Routing/Router.php:588
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Routing/Router.php:577
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:176
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:30
/home/vagrant/Code/forum/vendor/fideloper/proxy/src/TrustProxies.php:56
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:30
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:30
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php:27
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php:46
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:102
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:151
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:116
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php:294
/home/vagrant/Code/forum/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php:144
/home/vagrant/Code/forum/tests/Feature/ParticipateInForumTest.php:20


10th October, 2017

afonte15 left a reply on Dropping Foreign Keys • 1 week ago

It is laravel 5.2 but I will look into that. Thank you.

afonte15 left a reply on Dropping Foreign Keys • 1 week ago

I wrote it how you suggested and I doubled check mysql generated name and that is the correct generated name for the foreign key but I still get the same error.

create_inventories_table

 public function down()
    
    {
        Schema::table('inventories', function (Blueprint $table) {
            $table->dropForeign('inventories_employee_id_foreign');
            $table->dropColumn('employee_id');
        });

        Schema::drop('inventories');

    }
}

I even tried. But it still fails....

create_employees_table


public function down()
    {
        Schema::table('employees', function (Blueprint $table) {
            $table->dropForeign('inventories_employee_id_foreign');
           $table->dropColumn('inventories_employee_id');
        });

                Schema::drop('employees');
}
}

afonte15 started a new conversation Dropping Foreign Keys • 1 week ago

I have 5 tables and I am trying to drop foreign keys properly but I am unable to.

create_employees_table


<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateInventoriesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('inventories', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('employee_id')->unsigned();
            $table->integer('location_id')->unsigned();
            $table->integer('device_id')->unsigned();
            $table->foreign('employee_id')->references('id')->on('employees')->onDelete('cascade');
            $table->foreign('location_id')->references('id')->on('locations')->onDelete('cascade');
            $table->foreign('device_id')->references('id')->on('devices')->onDelete('cascade');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('inventories');
    }
}
    

ceate_locations_table


<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateLocationsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('locations', function (Blueprint $table) {
            $table->increments('locationId');
            $table->string('building', 25);
            $table->string('room',25);

        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('locations');
    }
}

create_devices_table


<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateDevicesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('devices', function(Blueprint $table) {
            $table->increments('deviceId');
            $table->string('manufacturer', 25);
            $table->string('device', 25);
            $table->string('model', 25);
            $table->string('tag', 25);
            $table->string('macAddress',17);
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('devices');
    }
}



create_status_table

20th June, 2017

afonte15 left a reply on Laravel Code - Vulnerable To Mysql Injections? • 3 months ago

Thank you. Will definitely be reading the link provided!

19th June, 2017

afonte15 started a new conversation Best Way To Display Search Results • 3 months ago

Hello, everyone.

I am trying to figure out if this is the best way to display search results?

 public function search()
    {
        $search = \Request::get('q'); //<-- we use global request to get the param of URI
//            $search = Input::get('search');
        $inventories = Inventory::where('lastName','LIKE','%'.$search.'%')
            -> orwhere('firstName', 'LIKE','%'.$search.'%' )
            -> orwhere('department', 'LIKE','%'.$search.'%' )
            -> orwhere('building', 'LIKE','%'.$search.'%' )
            -> orwhere('room', 'LIKE','%'.$search.'%' )
            -> orwhere('manufacturer', 'LIKE','%'.$search.'%' )
            -> orwhere('device', 'LIKE','%'.$search.'%' )
            -> orwhere('model', 'LIKE','%'.$search.'%' )
            -> orwhere('tag', 'LIKE','%'.$search.'%' )
            -> orwhere('macAddress', 'LIKE','%'.$search.'%' )
            -> orwhere('status', 'LIKE','%'.$search.'%' )
            -> orwhere('notes', 'LIKE','%'.$search.'%' )
            ->get();
        return view('computers.search',compact('inventories'));
    }

To display the results I am displaying it by location with the specific location link. So, if I would want to see all the computers located in VH, I click on the VH link on the menu. Is it optimal to do it this way, is it safe from mysql injections? Is there a better way to code the URLs? Is there a way to write it without the ? For example. http://inventory.app/computers/building/VH

<li><a href="http://inventory.app/computers?building=VH">VH</a></li>
<li><a href="http://inventory.app/computers?building=WH">WH</a></li>

routes.php

Route::auth();
Route::get('login', '[email protected]');
Route::post('login', '[email protected]_password');
Route::get('auth/logout', 'Auth\[email protected]');
Route::patch('computers/{inventories}', '[email protected]');
Route::get('computers/search', '[email protected]');
Route::resource('computers', 'InventoriesController');
Route::get('computers/create', '[email protected]');
Route::get('/home', '[email protected]');

afonte15 started a new conversation Laravel Code - Vulnerable To Mysql Injections? • 3 months ago

Hello,

Is my update code listed below vulnerable to mysql injections? Is this where I would protect my code from mysql injections? Thank you in advance for help.

public function update(InventoryRequest $request, Inventory $inventories){

    $inventories->update($request->all());

    flash('Success!', 'Inventory Successfully Updated!');
    return back();
}

20th April, 2017

afonte15 left a reply on Setting Up Vagrant/Homestead • 5 months ago

Issue is fixed! Needed to create a SSH key

afonte15 left a reply on Permission Denied - Laravel 5.2 - Vagrant • 5 months ago

Can I ask you one more question. I am setting up my development machine again.

Setting up vagrant/homestead

I ran bash init.sh and it said homestead initialized but when I try to navigate to the .homestead folder I get bash: cd: .homestead: No such file or directory

I am on Ubuntu 16.04

afonte15 left a reply on Permission Denied - Laravel 5.2 - Vagrant • 5 months ago

I run into this error when i have

class InventoriesController extends Controller
{
   public function __construct()
    {
        $this->middleware('auth');  
    }

But if I uncomment

class InventoriesController extends Controller
{
   public function __construct()
    {
        //$this->middleware('auth');  //does not allow users to login, redirects back to login when using LDAP credentials

    }

I am able to login and I receive no errors but then I am able to access the other web url without being logged in.

Any thoughts?

19th April, 2017

afonte15 started a new conversation Setting Up Vagrant/Homestead • 5 months ago

I am setting up Vagrant/Homestead on a Ubuntu 16.04.

I downloaded Homestead from the git repository

git clone https://github.com/laravel/homestead.git Homestead

I cd into the Homestead directory

Ran

bash init.sh

Received the message Homestead initialized!

but when I navigate to cd .homestead I get an error message that says

bash: cd: .homestead: No such file or directory

I also tried cd ~/.homestead still received the bash: cd: .homestead: No such file or directory

Any thoughts on how I can fix this?

afonte15 left a reply on Permission Denied - Laravel 5.2 - Vagrant • 5 months ago

[email protected]:~/sites/inventory/storage$ ls -l total 12

drwxr-xrwx 1 vagrant vagrant 4096 Mar  2 21:55 app
drwxr-xrwx 1 vagrant vagrant 4096 Mar  2 21:55 framework
drwxr-xrwx 1 vagrant vagrant 4096 Apr 18 02:04 logs
[email protected]:~/sites/inventory/storage$ cd framework
[email protected]:~/sites/inventory/storage/framework$ ls -l
total 12
drwxrwxrwx 1 vagrant vagrant 4096 Mar 10 20:55 cache
drwxrwxrwx 1 vagrant vagrant 4096 Apr 19 01:31 sessions
drwxrwxrwx 1 vagrant vagrant 4096 Apr 19 01:31 views
[email protected]:~/sites/inventory/storage/framework$ cd sessions
[email protected]:~/sites/inventory/storage/framework/sessions$ ls -l
total 20
-rw-r--r-- 1 vagrant vagrant 197 Apr 19 01:30 074589b8bef8732a3a55eaca60ceaa9e2adb4610
-rw-r--r-- 1 vagrant vagrant 360 Apr 19 01:31 21c72020b901982cd900a79aef6151ea0cd9ed72
-rw-r--r-- 1 vagrant vagrant 268 Apr 19 01:31 236b18b7007d091ef48d2d863627e545286c39e1
-rw-r--r-- 1 vagrant vagrant 349 Apr 19 01:31 f0d71b09248682b4a9688510fcd4c3001e20682a
-rw-r--r-- 1 vagrant vagrant 268 Apr 19 01:31 ff658e4153dbe2a47c29e631e8d583919f9cd549
[email protected]:~/sites/inventory/storage/framework/sessions$ 

afonte15 left a reply on Permission Denied - Laravel 5.2 - Vagrant • 5 months ago


[2017-04-19 01:31:38] local.ERROR: ErrorException: file_put_contents(/home/vagrant/sites/inventory/storage/framework/sessions/ff658e4153dbe2a47c29e631e8d583919f9cd549): failed to open stream: Permission denied in /home/vagrant/sites/inventory/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php:111
Stack trace:
#0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'file_put_conten...', '/home/vagrant/s...', 111, Array)
#1 /home/vagrant/sites/inventory/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php(111): file_put_contents('/home/vagrant/s...', 'a:4:{s:6:"_toke...', 2)
#2 /home/vagrant/sites/inventory/vendor/laravel/framework/src/Illuminate/Session/FileSessionHandler.php(83): Illuminate\Filesystem\Filesystem->put('/home/vagrant/s...', 'a:4:{s:6:"_toke...', true)
#3 /home/vagrant/sites/inventory/vendor/laravel/framework/src/Illuminate/Session/Store.php(262): Illuminate\Session\FileSessionHandler->write('ff658e4153dbe2a...', 'a:4:{s:6:"_toke...')
#4 /home/vagrant/sites/inventory/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(88): Illuminate\Session\Store->save()
#5 /home/vagrant/sites/inventory/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(155): Illuminate\Session\Middleware\StartSession->terminate(Object(Illuminate\Http\Request), Object(Illuminate\Http\RedirectResponse))
#6 /home/vagrant/sites/inventory/public/index.php(48): Illuminate\Foundation\Http\Kernel->terminate(Object(Illuminate\Http\Request), Object(Illuminate\Http\RedirectResponse))
#7 {main}  
[2017-04-19 01:31:38] local.ERROR: ErrorException: file_put_contents(/home/vagrant/sites/inventory/storage/framework/sessions/21c72020b901982cd900a79aef6151ea0cd9ed72): failed to open stream: Permission denied in /home/vagrant/sites/inventory/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php:111
Stack trace:
#0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'file_put_conten...', '/home/vagrant/s...', 111, Array)
#1 /home/vagrant/sites/inventory/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php(111): file_put_contents('/home/vagrant/s...', 'a:5:{s:6:"_toke...', 2)
#2 /home/vagrant/sites/inventory/vendor/laravel/framework/src/Illuminate/Session/FileSessionHandler.php(83): Illuminate\Filesystem\Filesystem->put('/home/vagrant/s...', 'a:5:{s:6:"_toke...', true)
#3 /home/vagrant/sites/inventory/vendor/laravel/framework/src/Illuminate/Session/Store.php(262): Illuminate\Session\FileSessionHandler->write('21c72020b901982...', 'a:5:{s:6:"_toke...')
#4 /home/vagrant/sites/inventory/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(88): Illuminate\Session\Store->save()
#5 /home/vagrant/sites/inventory/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(155): Illuminate\Session\Middleware\StartSession->terminate(Object(Illuminate\Http\Request), Object(Illuminate\Http\RedirectResponse))
#6 /home/vagrant/sites/inventory/public/index.php(48): Illuminate\Foundation\Http\Kernel->terminate(Object(Illuminate\Http\Request), Object(Illuminate\Http\RedirectResponse))
#7 {main}  
[2017-04-19 01:31:38] local.ERROR: ErrorException: file_put_contents(/home/vagrant/sites/inventory/storage/framework/sessions/f0d71b09248682b4a9688510fcd4c3001e20682a): failed to open stream: Permission denied in /home/vagrant/sites/inventory/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php:111
Stack trace:
#0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'file_put_conten...', '/home/vagrant/s...', 111, Array)
#1 /home/vagrant/sites/inventory/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php(111): file_put_contents('/home/vagrant/s...', 'a:5:{s:6:"_toke...', 2)
#2 /home/vagrant/sites/inventory/vendor/laravel/framework/src/Illuminate/Session/FileSessionHandler.php(83): Illuminate\Filesystem\Filesystem->put('/home/vagrant/s...', 'a:5:{s:6:"_toke...', true)
#3 /home/vagrant/sites/inventory/vendor/laravel/framework/src/Illuminate/Session/Store.php(262): Illuminate\Session\FileSessionHandler->write('f0d71b09248682b...', 'a:5:{s:6:"_toke...')
#4 /home/vagrant/sites/inventory/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(88): Illuminate\Session\Store->save()
#5 /home/vagrant/sites/inventory/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(155): Illuminate\Session\Middleware\StartSession->terminate(Object(Illuminate\Http\Request), Object(Illuminate\Http\Response))
#6 /home/vagrant/sites/inventory/public/index.php(48): Illuminate\Foundation\Http\Kernel->terminate(Object(Illuminate\Http\Request), Object(Illuminate\Http\Response))
#7 {main}  

afonte15 left a reply on Permission Denied - Laravel 5.2 - Vagrant • 5 months ago

I am at the login page and I provide the credentials to login and it just redirects back to the login page. Password is correct and then I check my laravel.log file and I get that permission error.

afonte15 left a reply on Permission Denied - Laravel 5.2 - Vagrant • 5 months ago

When I originally got the error I tried changing the permissions to the storage and boostrap/cache folder

afonte15 left a reply on Permission Denied - Laravel 5.2 - Vagrant • 5 months ago

[email protected]:~/sites/inventory$ ls -l total 204

drwxrwxrwx 1 vagrant vagrant   4096 Apr 13 14:17 app
-rw-rw-r-- 1 vagrant vagrant   1646 Jul 27  2016 artisan
drwxrwxrwx 1 vagrant vagrant   4096 Jul 27  2016 bootstrap
-rw-rw-r-- 1 vagrant vagrant   1386 Nov 30 22:07 composer.json
-rw-rw-r-- 1 vagrant vagrant 116748 Mar 21 16:55 composer.lock
drwxrwxr-x 1 vagrant vagrant   4096 Apr 18 15:34 config
drwxrwxr-x 1 vagrant vagrant   4096 Jul 27  2016 database
-rw-rw-r-- 1 vagrant vagrant    658 Aug 12  2016 gulpfile.js
drwxrwxr-x 1 vagrant vagrant  24576 Jul 27  2016 node_modules
-rw-rw-r-- 1 vagrant vagrant    212 Jul 27  2016 package.json
-rw-rw-r-- 1 vagrant vagrant   1026 Jul 27  2016 phpunit.xml
drwxrwxr-x 1 vagrant vagrant   4096 Aug  9  2016 public
-rw-rw-r-- 1 vagrant vagrant   1918 Jul 27  2016 readme.md
drwxrwxr-x 1 vagrant vagrant   4096 Jul 27  2016 resources
-rw-rw-r-- 1 vagrant vagrant    567 Jul 27  2016 server.php
drwxrwxrwx 1 vagrant vagrant   4096 Jul 27  2016 storage
drwxrwxr-x 1 vagrant vagrant   4096 Jul 27  2016 tests
drwxrwxrwx 1 vagrant vagrant   4096 Mar 21 16:55 vendor

afonte15 left a reply on Permission Denied - Laravel 5.2 - Vagrant • 5 months ago

[email protected]:~/sites/inventory$ ls -l total 204 drwxrwxrwx 1 vagrant vagrant 4096 Apr 13 14:17 app -rw-rw-r-- 1 vagrant vagrant 1646 Jul 27 2016 artisan drwxrwxrwx 1 vagrant vagrant 4096 Jul 27 2016 bootstrap -rw-rw-r-- 1 vagrant vagrant 1386 Nov 30 22:07 composer.json -rw-rw-r-- 1 vagrant vagrant 116748 Mar 21 16:55 composer.lock drwxrwxr-x 1 vagrant vagrant 4096 Apr 18 15:34 config drwxrwxr-x 1 vagrant vagrant 4096 Jul 27 2016 database -rw-rw-r-- 1 vagrant vagrant 658 Aug 12 2016 gulpfile.js drwxrwxr-x 1 vagrant vagrant 24576 Jul 27 2016 node_modules -rw-rw-r-- 1 vagrant vagrant 212 Jul 27 2016 package.json -rw-rw-r-- 1 vagrant vagrant 1026 Jul 27 2016 phpunit.xml drwxrwxr-x 1 vagrant vagrant 4096 Aug 9 2016 public -rw-rw-r-- 1 vagrant vagrant 1918 Jul 27 2016 readme.md drwxrwxr-x 1 vagrant vagrant 4096 Jul 27 2016 resources -rw-rw-r-- 1 vagrant vagrant 567 Jul 27 2016 server.php drwxrwxrwx 1 vagrant vagrant 4096 Jul 27 2016 storage drwxrwxr-x 1 vagrant vagrant 4096 Jul 27 2016 tests drwxrwxrwx 1 vagrant vagrant 4096 Mar 21 16:55 vendor

afonte15 left a reply on Permission Denied - Laravel 5.2 - Vagrant • 5 months ago

It seems like the webserver doesn't have permission to write to storage...what is the webserver needs write access. Do you know how I can change permission for my webserver to have access?

afonte15 left a reply on Permission Denied - Laravel 5.2 - Vagrant • 5 months ago

Yes. I have run it a few times at this point. Hoping that would resolve the issue. Do you know if the permission changes should be done on the host machine or the vagrant machine?

afonte15 left a reply on Permission Denied - Laravel 5.2 - Vagrant • 5 months ago

Yes, that is how I have always done it as well.

The error refers to a line in the filesystem.php file. Line 111

public function put($path, $contents, $lock = false)
    {
        return file_put_contents($path, $contents, $lock ? LOCK_EX : 0); //line 111
    }

afonte15 left a reply on Permission Denied - Laravel 5.2 - Vagrant • 5 months ago

At this point I ran the permission change on both the host and vagrant box.

What is the correct way to run the permission change commands? On my host machine which is also Ubuntu or do I change the permissions in vagrant once I SSH into it?

When I created my laravel project, when I run php artisan laravel new blog I ran that command in vagrant. Should I have ran that command on my host machine?

Is there a way to avoid this issue in the future?

18th April, 2017

afonte15 left a reply on Permission Denied - Laravel 5.2 - Vagrant • 6 months ago

I get the same errors after changing the permissions. Any help would be appreciated! I have been stuck on this for weeks now.

afonte15 left a reply on Permission Denied - Laravel 5.2 - Vagrant • 6 months ago

I also ran the command below on the bootstrap/cache

sudo chmod -R o+w storage/

afonte15 started a new conversation Permission Denied - Laravel 5.2 - Vagrant • 6 months ago

local.ERROR: ErrorException: file_put_contents(/home/vagrant/sites/inventory/storage/framework/sessions/d32af67dfac92893bf1eec9768bec180cdc34e88): failed to open stream: Permission denied in /home/vagrant/sites/inventory/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php:111

I have changed permissions. I tried

sudo chmod -R o+w storage/

and

php artisan cache:clear php artisan clear-compiled

sudo chmod -R 777 storage/ composer dump-autoload

This does not fix the issue. Any help would be appreciated.

My host machine is Ubuntu 16.04

Laravel 5.2

10th April, 2017

afonte15 left a reply on Laravel Login Redirects To Blank Page • 6 months ago

That is the error?


/home/vagrant/sites/inventory/storage/framework/views/a3058f755df9fe906eefaef2dc67bb072f13153f.php:68:
object(Illuminate\Support\ViewErrorBag)[151]
  protected 'bags' => 
    array (size=0)
      empty

afonte15 left a reply on Laravel Login Redirects To Blank Page • 6 months ago

' ' 'php /home/vagrant/sites/inventory/storage/framework/views/a3058f755df9fe906eefaef2dc67bb072f13153f.php:68: object(Illuminate\Support\ViewErrorBag)[151] protected 'bags' => array (size=0)

'''

afonte15 left a reply on Laravel Login Redirects To Blank Page • 6 months ago

I get an ldap invalid credentials error.

ldap_bind(): Unable to bind to server: Invalid credentials

afonte15 left a reply on Laravel Login Redirects To Blank Page • 6 months ago

This is what displays as the error.

ViewErrorBag {#151 ▼ #bags: [] }

afonte15 left a reply on Laravel Login Redirects To Blank Page • 6 months ago

I added use App\User; and that cleared up the error with the LoginController but now after I login it just redirects back to the login page.

When I check the network tab in my browser I get a

302 Found message on Post

And on Get I get a

200 OK

any thoughts. Possibly something with my middleware now?

afonte15 left a reply on Laravel Login Redirects To Blank Page • 6 months ago

Ok so, I thought Chmod -R 777 permission is never good to do.

I ran sudo chmod -R o+w storage/

and now after I hit login I am getting this error

FatalThrowableError in LoginController.php line 25: Class 'App\Http\Controllers\User' not found

This is progress, right? Now I am seeing an error and it seems to be an issue with my LoginController.php file.

afonte15 left a reply on Laravel Login Redirects To Blank Page • 6 months ago

I will give this a try. Yea, Homestead usually never gives me trouble. I hadn't coded for awhile and getting back into things but I already thought I adjusted my folder permissions because before this issue I was getting blank page even at start up. I will take a look at the link and most likely try your suggestion.

afonte15 left a reply on Laravel Login Redirects To Blank Page • 6 months ago

Yes, I am using Homestead.

9th April, 2017

afonte15 left a reply on Laravel Login Redirects To Blank Page • 6 months ago

laravel.log file located in app/storage/app/logs

[2017-04-03 13:10:38] local.ERROR: ErrorException: file_put_contents(/home/vagrant/sites/inventory/storage/framework/sessions/8f709f9d4f445d2772ed7f48bbb9c4bff8a63819): failed to open stream: Permission denied in /home/vagrant/sites/inventory/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php:111
Stack trace:
#0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'file_put_conten...', '/home/vagrant/s...', 111, Array)
#1 /home/vagrant/sites/inventory/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php(111): file_put_contents('/home/vagrant/s...', 'a:4:{s:6:"_toke...', 2)
#2 /home/vagrant/sites/inventory/vendor/laravel/framework/src/Illuminate/Session/FileSessionHandler.php(83): Illuminate\Filesystem\Filesystem->put('/home/vagrant/s...', 'a:4:{s:6:"_toke...', true)
#3 /home/vagrant/sites/inventory/vendor/laravel/framework/src/Illuminate/Session/Store.php(262): Illuminate\Session\FileSessionHandler->write('8f709f9d4f445d2...', 'a:4:{s:6:"_toke...')
#4 /home/vagrant/sites/inventory/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(88): Illuminate\Session\Store->save()
#5 /home/vagrant/sites/inventory/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(155): Illuminate\Session\Middleware\StartSession->terminate(Object(Illuminate\Http\Request), Object(Illuminate\Http\Response))
#6 /home/vagrant/sites/inventory/public/index.php(48): Illuminate\Foundation\Http\Kernel->terminate(Object(Illuminate\Http\Request), Object(Illuminate\Http\Response))
#7 {main}  

afonte15 left a reply on Laravel Login Redirects To Blank Page • 6 months ago

After I login I am getting a 500 Internal Server Error

afonte15 left a reply on Laravel Login Redirects To Blank Page • 6 months ago

I am not using an LDAP package.

afonte15 left a reply on Laravel Login Redirects To Blank Page • 6 months ago

I am using laravel 5.2.

I have removed the web middleware from my routes.php file and the same thing still happens. I get redirected to a blank page and the url is my login page. But I can still access my other pages when I change the url after the login redirect to the blank page.

My logout redirect works and it redirects me to the login page.

In my InventoriesController.php if I uncomment "this->middleware('auth'); then I cannot get passed the login page. After I try logging in it redirects back to the login page and actually displays the page. But I cannot access any other pages even when changing the urls manually.


<?php

namespace  App\Http\Controllers;

use Illuminate\Http\Request;
use DB;
use App\Inventory;
use App\Http\Requests\InventoryRequest;
class InventoriesController extends Controller
{
   public function __construct()
    {
        //$this->middleware('auth');  //does not allow users to login, redirects back to login when using LDAP credentials

    }

I am not sure if this makes a difference but when I list my routes in the terminal under name nothing is listed. the URI is listed as computers/create but for under name it is blank.

<blockquote class="imgur-embed-pub" lang="en" data-id="a/f5TG9"><a href="//imgur.com/f5TG9"></a></blockquote><script async src="//s.imgur.com/min/embed.js" charset="utf-8"></script>

8th April, 2017

afonte15 started a new conversation Laravel Login Redirects To Blank Page • 6 months ago

Hello Everyone,

I have been stuck with Laravel redirecting after login. The connection works and after I login it redirects to a blank page but if I change the url path I can access the different web pages. Any assistance would be highly appreciated! I am using LDAP to connect and it is working. On my AuthController I have the protected $redirectTo paths set. See picture below. enter image description here

Please let me know if there is any other code I should provide.

Thank you!!!


<?php

namespace App\Http\Middleware;

use Closure; use Illuminate\Support\Facades\Auth;

class RedirectIfAuthenticated {

protected $auth; /**

Handle an incoming request.
@param \Illuminate\Http\Request $request
@param \Closure $next
@param string|null $guard
@return mixed */

public function handle($request, Closure $next, $guard = null) 
{
     if (Auth::guard($guard)->check()) { 
        return redirect('/computers/create'); 
    }

    return $next($request); 
    }

} 

7th April, 2017

afonte15 left a reply on Laravel Login Redirects To Blank Page • 6 months ago

Login
                    {{ csrf_field() }}


                    <div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
                        <label for="userName" class="col-md-4 control-label">Ad username</label>

                        <div class="col-md-6">
                            <input id="userName"  class="form-control" name="userName" value="{{ old('email') }}">

                            @if ($errors->has('userName'))
                                <span class="help-block">
                                    <strong>{{ $errors->first('userName') }}</strong>
                                </span>
                            @endif
                        </div>
                    </div>

                    <div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
                        <label for="password" class="col-md-4 control-label">Password</label>

                        <div class="col-md-6">
                            <input id="password" type="password" class="form-control" name="password">

                            @if ($errors->has('password'))
                                <span class="help-block">
                                    <strong>{{ $errors->first('password') }}</strong>
                                </span>
                            @endif
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-md-6 col-md-offset-4">
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" name="remember"> Remember Me
                                </label>
                            </div>
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-md-6 col-md-offset-4">
                            <button type="submit" class="btn btn-primary">
                                <i class="fa fa-btn fa-sign-in"></i> Login
                            </button>

                            <a class="btn btn-link" href="{{ url('/password/reset') }}">Forgot Your Password?</a>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
@endsection

afonte15 left a reply on Laravel Login Redirects To Blank Page • 6 months ago

I cannot get the code to post correctly. I am trying to paste the login.blade.php but can't at the moment.

Edit Your Profile
Update

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