jordano1

jordano1

Member Since 3 Years Ago

Experience Points 5,140
Experience Level 2

4,860 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 52
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

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

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

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

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

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

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

27 Mar
1 year ago

jordano1 left a reply on Download A File From The Database

I don't think I originally understood bobby's response, but he did help me get to an answer, ultimately I simplified my storeAs method in filescontroller to:

            $fileLoc =  $request->file->storeAs('/upload/', $originalName);

and then made sure my download method was properly going to the files path:

    public function download($file)
    {
      return response()->download(storage_path("app/upload/{$file}"));
        // view("files.download", compact('$download'));
    }

Once I did this, I was able to get the files downloaded that were stored.

Thanks.

26 Mar
1 year ago

jordano1 left a reply on Download A File From The Database

There is a temporary folder that is storing the files I'm uploading, I may have said in a weird way, it's in the public folder. So in my public folder I have storage/upload directories and in upload is where the files are being stored currently.

jordano1 left a reply on Download A File From The Database

Hey Bob, thanks for the response. When I put the path into my file it says the file doesn't exist, so I'm wondering if I'm doing this wrong and how do it correctly

in my download function:

    public function download($file)
    {
        $url = Storage::url($file);


        $download=DB::table('files')->get();
        return response()->download("storage/app/upload$url");
        // view("files.download", compact('$download'));
    }

I'm getting errors that the file doesn't exist, how would I get the path to my file? I tried putting the $url var in but it just gives me another error.

Am I getting the path incorrectly?

(1/1) FileNotFoundException
The file "/storage/East Coast Defender-loop.jpg" does not exist

jordano1 started a new conversation Download A File From The Database

I have a FileController, a file.blade.php and 3 routes.

3 routes:


Route::get('/file-upload/', '[email protected]'); //this is returning the file-upload page with the files laid out in a foreach loop

Route::get('/file-upload/download/{file}', '[email protected]');//this route will fire when the user clicks to download a file on the file-upload page```

uploading a file will trigger this method:

```public function store(Request $request)
     {
  
        $files = Files::all();
        if($request->hasFile('file') && $request->file('file')->isValid()){
            //
            //storing the input field with the name "file" in $file.
            $file = $request->file('file');
            //using laravel method to get filename from the inputfield, in case we add a feature to allow the user to provide the name
            $originalName = $file->getClientOriginalName();

            //storing file in public/upload saving as $originalName
            $fileLoc =  $request->file->storeAs('public/upload', $originalName);
            //getting mimetype from the file stored with the class storage using method mimetype of the file above
            $mimeType = Storage::mimeType($fileLoc);

            //creating a new file entry
            $entry = new Files();
            //storing mimetype of file
            $entry->mime = $mimeType;
            //storing filename of file
            $entry->original_filename =  $originalName;
            //storing name as ogname, but may change to allow users to name file
            $entry->name = $originalName;
            //saving and making entry to the DB
            $entry->save();

        }else{
            //if statement checks if file is a file and is valid, otherwise no file to upload
            return "Failed to upload";

        }
        return back(); compact('files');
    }```



When a user clicks on a file they uploaded:

```public function download($file)
    {
      $url = Storage::url($file);


        $download=DB::table('files')->get();
        return Storage::download($url);
        // view("files.download", compact('$download'));
    }```

I have confirmed via sequel pro that this works, the entry is recorded in the database, in the public/upload directory in public/storage/upload/(filesstoredhere), and displayed in the view.

the view file.blade.php (relevance to question, took out elements not applicable to issue):
```<form method="POST" action="/file-upload/" >
  
                                  <input id="input-fa" name="file" type="file" class="validate" enctype="multipart/form-data">
                            

</form>
    <div class="col-sm">
      <a href="file-upload/download/{{$file->name}}" download="{{$file->name}}">
          <button type="button" class="btn btn-primary"><i class="glyphicon glyphicon-download">download</i></button>
      </a>

I'm not sure if I should be using in the href element the "download" property with the $file->name. This seems to download the file, but it will say that the file "filename.jpg" could not be opened because it is empty.

I tried using the download function but I just get the error: (1/1) BadMethodCallException Call to undefined method League\Flysystem\Filesystem::download

Any help would be appreciated, if you need more info let me know.

Thanks!

21 Nov
1 year ago

jordano1 left a reply on Keeping Correct Data On Views

Thanks design-studio, the redirect methods helped fulfill what I wanted to do, I really appreciate it!

19 Nov
1 year ago

jordano1 left a reply on Keeping Correct Data On Views

So I fixed this by creating 2 variables on softdelete:

$users = User::all(); $trashed_users = User::onlyTrashed()->get(); return view('home', compact('users', 'trashed_users'));

These variables already exist on index, is there a way I can have all my views or certain views to always have the variables they need so I don't get errors?

18 Nov
1 year ago

jordano1 left a reply on Keeping Correct Data On Views

If you need to see all the code:

[email protected]:jordano1/asset-repo.git https://bitbucket.org/jordano1/asset-repo

I am struggling in understanding why in the view I have to return $users every time, after I click on any submission or form or get to a different page. I just want home.blade.php to have the required data passed from the controller, but I keep messing up and moving between route/model binding for efficiency but then I'll get errors because I don't fully understand how to implement some of this. I went to the docs and didn't really get much help there.

jordano1 started a new conversation Keeping Correct Data On Views

I'm accessing the database and getting all my users by doing this:

public function index(User $users)
    {
        //storing all users from the database as $user
        $users = User::all();
        //storing all trashed users in the trashed_users var
        $trashed_users = User::onlyTrashed()->get();
        //return home with a users array and trashed users array for the foreach loops on the homepage
        return view('home', compact('users', 'trashed_users'));
    }

$users = User::all(); is getting all the users

My routes file web.php

Route::get('/delete/{user}/softDelete', '[email protected]');
Route::post('/delete/{user}/softDelete', '[email protected]');

home is spitting out all the users with a foreach loop, and each user has their own associated information for each, but for some reason, whenever I click to delete, which will take me to the above softDelete route, I get an error, the URL is not giving the user id, it's giving me this:

http://asset-repo.app/delete/%7Buser%7D/softDelete

I am guessing I cannot use route model binding here? My work around was to replace the {user} with {{$user->id}} which gives the user ID, and the users information, but this feels wrong to me.

home.blade

<p>ID: {{$user->id}}</p>
                            <form method="POST" action="/delete/{user}/softDelete">
                                {{ csrf_field() }}
                                <button type="submit" class="btn btn-danger">Delete</button>
                            </form>

If I use the above workaround (replace the {user} with {{$user->id}} only in home.blade.php) it will delete the user but I will get an error because the foreach loop needs the user variable, but I thought this was returned through the above index method.

The exact error is:

http://jordanodesign.com/for-the-luls/laravel-error.png

jordano1 left a reply on Route Model Binding With Soft Deleted Model

Thanks all, Snapey's answer helped but I gave all of you upvotes for your participation.

16 Nov
1 year ago

jordano1 left a reply on Route Model Binding With Soft Deleted Model

Thanks guys, I'll try using Snapey's code and see if it works when I get to a computer. I really appreciate the help! I'll put snapey's as the answer if this works.

15 Nov
1 year ago

jordano1 left a reply on Route Model Binding With Soft Deleted Model

Tykus I am not sure how to implement binding, what I can do with this function, and why I need to bind it, I read some of the explicitly bind documentation but I don't totally follow it.

I looked at the docs and added the bottom function. Added the function as per the docs web.php file:

Route::get('/restore/{user}/restoreUser', '[email protected]');
Route::post('/restore/{user}/restoreUser', '[email protected]');

Route::get('/restore/{user}/restoreUser', function (App\User $user) {
    //
});

routeserviceprovider.php

public function boot() { // parent::boot();

    Route::bind('trashed_user', function ($id) {
        return User::onlyTrashed()->find($id);
    });
    
}

I'm still not getting the data I need to restore the user. 

jordano1 started a new conversation Route Model Binding With Soft Deleted Model

Route Model binding with soft deleted model home.blade file:

<form method="POST" action="/restore/{{$trashed_user->id}}/restoreUser">
{{ csrf_field() }}
<button type="submit" class="btn btn-info">Restore User</button>
</form>

routes/web.php file:

Route::get('/restore/{user}/restoreUser', '[email protected]');
Route::post('/restore/{user}/restoreUser', '[email protected]');

HomeController

    public function restore(User $user)
    {    
        $user->restore();   
        return view('restore.restoreUser');
    }

Few questions here: Q1: do I need a csrf_field on each of these forms? Q2: Can you actually do route model binding with trashed users? I've seen people talk about {bind} but I'm not really sure how that works, I kinda get lost with it.

Things I have tried: changing the view's form action to /restore/{user}/restoreUser, and gone through the process in getting the correct ID, but the only way I can actually get the ID is by making a variable called "trashed_users" but I'm not sure how I can get the restore function working.

If you need to see my index function, where the trashed_users variable is stored, it's right here:

   public function index()
    {
        //storing all users from the database as $user
        $users = User::all();
        //storing all trashed users in the trashed_users var
        $trashed_users = User::onlyTrashed()->get();
        //return home with a users array and trashed users array for the foreach loops on the homepage
        return view('home', compact('users', 'trashed_users'));
    }
07 Nov
1 year ago

jordano1 left a reply on User Roles

Hey mushood, thanks for responding.

Q3: I mean that for my users with instructor roles being able to upload their own content and I was just wondering if there was a solution for that I could use or if I needed to create some kind of form that asks users to upload content. The idea is to have Instructors being able to upload files like videos and audio so students can download them for classes and stuff.

jordano1 started a new conversation User Roles

All I've done is laravel new and make:auth. I have spent a lot of time trying to understand how to get this functional, but I'm getting no where. I am building a site for an educational group that needs to manage their assets, they would like, I guess 3 levels of access?

  1. user (registers to the site, can read and download files associated to whatever class they're taking from the professor)

  2. instructors (users can become instructors by sending an email to the administrator, and having the admin give the access to the user. Instructors can post and update only their own content)

  3. admin (has the ability to set users role and delete their accounts)

I've looked around some and noticed a few things, what if the admin gets deleted? Do you just create a new one on the back end?

I have 2 controllers, a User controller from make:auth and I created a Role controller so I can set up the relationship between the two, which I followed along here: https://laravel.com/docs/5.5/eloquent-relationships and read roles are generally belongsToMany. In both my controllers I have the relationship set as belongsToMany.

I have 3 migrations, users, password resets, and roles. I watched this video: https://laracasts.com/series/laravel-from-scratch-2017/episodes/30 and Jeffery talks about a pivot table, I went ahead and created the pivot table inside of my roles table, which is just integer('user_id');, integer('role_id');, and a primary(['user_id', 'role_id']);

I'm basically just trying to build some simple functionality at the moment, like creating a new user with an admin role, but I don't even know how to do that, my migrations worked and all my tables are showing, but I'm not 100% sure what to do next, how do I create a user with the admin role? My roles table looks like this:

<?php

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

class CreateRolesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('roles', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name')->unique();
            $table->timestamps();
        });

        Schema::create('user_roles', function (Blueprint $table) {
            $table->integer('user_id');
            $table->integer('role_id');
            $table->primary(['user_id', 'role_id']);
        });
    }

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

Question 1: I'm using the latest Laravel 5.5.3, and I saw another video where Jeffery just did php artisan generate:pivot or something like that, is there a command still you can write for pivot tables or do you just generally create a table with 2 ints holding the id's of what you want associated, and a primary key for both?

Question 2: do I need to have the 'user', 'instructor', admin' roles as things in my database? All I have in there right now is that it has to be a unique name: $table->string('name')->unique();

Question 3: for uploading files and content, does laravel have some kind of plugin you can use to mass upload files? The group I'm making this site for has lots of audio video and ppt files, I wonder is there a simple solution to going about uploading content to the site?

Question 4: If I have a user who uploads an audio file or video file, those things take a ton of space, how do you efficiently store things like that? Is there a way?

Thanks for any help!

06 Jun
2 years ago

jordano1 left a reply on Need Some Clarification On Carbon, And What's The Best Way To Get/post An Action Through Web Routes

Wow. I spent hours reluctantly seeking help, and here I am, wishing I did this hours ago. Thank you all so much, I appreciate it.

jordano1 started a new conversation Need Some Clarification On Carbon, And What's The Best Way For Get/post An Action Through Web Routes

I have a Posts model, and a PostsController

Here's the model:

<?php

namespace App;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;


class Posts extends Model
{
    //
    protected $fillable = ['email', 'created_at'];
    protected $dates = ['created_at', 'updated_at', 'done_at', 'disabled_at'];

}

here's the controller:

<?php

namespace App\Http\Controllers;

use DB;
use App\Posts;
use Illuminate\Http\Request;
use Carbon\Carbon;

class PostsController extends Controller
{
    public function index()
    {
        return view('index');
    }
    
    public function ty(Request $request)
    {
        $all = DB::table('posts')->get();
        $dates = DB::table('posts')->select('created_at')->get();
        return view('ty', compact('all'));
    }
    public function store(Request $request)
    {
        
        $all = DB::table('posts')->get();
        $this->validate($request, [
            'email' => 'required | unique:posts',
        ]);
        Posts::create([
            'email' => request('email')
        ]);
        //$post->time = request('timestamps');
        return view('ty', compact('all'));
    }

and then the layout:

@foreach($all as $posts)
    <tr>
      <td>{{$posts->email}}</td>
      <td>{{Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $posts->created_at)->diffForHumans()}}</td>
      <td>{{$posts->updated_at}}</td>
    </tr>
  @endforeach

So my problem with Carbon, is that on that 2nd I had to write that whole line to convert it, when it should be already converted, but if I were to just write out:

$posts->created_at->diffForHumans()}}

I get the error:

"Call to a member function diffForHumans() on string (View: /home/vagrant/Code/group-project-laravel/resources/views/ty.blade.php)"

but I thought that when you added a protected $dates field in your model, as I have done, it kept those fields as date time objects, therefor allowing you the ability to use the diffForHumans(). I think the problem is that I'm using compact, but I'm not totally sure. The problem here is I use compact a lot, and this is the biggest problem, I wonder if it's having an affect on it being converted while it's a protected property?

My other question is that I am using two routes for my ty page:

Route::get('/ty', '[email protected]');
Route::post('/ty', '[email protected]');

Is there a better way to do this? Do you really need to have two routes? I get they are both different, one is a get request the other is a post request, but can I combine the two into one statement? I don't know that it's a huge deal, but I just want to be following best practices.

25 Feb
2 years ago

jordano1 left a reply on Column Sorting With Pagination On Laravel 5.1

jlrdw seems like he's got a rod up his ass

18 Sep
2 years ago

jordano1 left a reply on Running Into Windows 10 Vagrant Homestead Laravel Issues (mainly From The .yaml And Displaying In The Browser)

Ok, well, I'm aware of how to reference the files using forward slashes. I'll go through this laravelista documentation and see if I can get anywhere with it. I'll update the thread if this answers my question.

jordano1 started a new conversation Running Into Windows 10 Vagrant Homestead Laravel Issues (mainly From The .yaml And Displaying In The Browser)

Hey guys, I setup vagrant and spent several hours last night trying to configure Vagrant with Homestead, and then I installed the laravel master file to just play around with the code and get myself familiar with the environment. So far I can't even bring up the homestead.app view. I have just a few general questions.

To get your questions for me out of the way, I'll start off by saying the things I did correctly: (essentially I did everything in the tutorial, I just think maybe I got confused and messed up something at some point)

  1. I created an SSH key, the key is already mapped correctly.

  2. I have ran "vagrant reload -- provision" to restart my VM, I have ssh'd into my VM to see if folders are synchronizing (which they are not, I clarify on this below).

  3. I added the ip path to my hosts file.

  4. Should there be two homestead.yaml files? I have one that's in my Homestead directory which I created on my Desktop, but I also have one in my Home ("C:\Users\Jordan.homestead\Homestead.yaml"). I've tried figuring out if they are supposed to reference each other by deleting one and re-initializing but it just reinitialize with the data I put into it, so if I make a mistake, I can't just delete it and reinitialize it.

If this is the case, then which am I supposed to update? Why are there two files?

  1. vagrant up works, and my virtual machine works, but when I SSH into my virtual box, I'm not seeing the sync'd folders such as "/home/vagrant/Code" or "/home/vagrant/Code/Laravel/Public". Neither of these paths exist so I'm wondering if the yaml file I'm working on is the wrong one, but just to add some clarification, I made the changes to BOTH of my yaml files.

my yaml folders / sites section is configured as: folders: - map: ~/Desktop/laravel-master to: /home/vagrant/Code

sites: - map: projects.dev to: /home/vagrant/Code/Laravel/public

I am mapping my desktop 'laravel-master' folder which I got from github to the vagrant code directory on my VM. Does it matter I changed the site to "-map:projects.dev" rather than "-map:homestead.app"?

Additional questions: Thanks for reading through if you did, I'm losing my mind here. I think the confusing part for me is

  1. how does it display in my browser if it's running from the VM?
  2. Am I supposed to manually put my files in my VM? Or is the whole reason we have this YAML file to avoid doing that?
  3. How is it that it maps my browser to use the localhost configuration for a VM?

Thanks