Tommy001

Tommy001

Member Since 1 Year Ago

Experience Points 3,910
Experience Level 1

1,090 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 26
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.

28 Mar
2 months ago

Tommy001 left a reply on How To Pass A Js Variable Into A Vue.js Instance?

No, unfortunately the same thing:

Undefined index: nextIndex

If I just replace nextIndex with a number it works as expected, url is passed to the href link, like this:

<a v-bind:href="url">

But I need to alter the index dynamically, and I Just can't figure out how to use a JS variable in the blade syntax.

Tommy001 left a reply on How To Pass A Js Variable Into A Vue.js Instance?

Thanks, but that gives me the same error message as before:

Use of undefined constant nextIndex

Tommy001 started a new conversation How To Pass A Js Variable Into A Vue.js Instance?

In my blade template I have a javascript snippet that produces a variable that holds an index, to be used in an array. I would like to use that index in a Vue instance, like this:

    var app = new Vue({
        el: '#root',
        data: {
            url: "{{route('showphoto')}}/{{$photos[nextIndex]->id}}"
        }
    });

So, how can I pass the JS variable nextIndex into the vue data above?

27 Mar
2 months ago

Tommy001 left a reply on Use Vue In Blade To Add A Photo Id After A Route In A Href Link

Sorry about the noise... Figured it out... changing the link like this:

<a v-bind:href="url">

and then changing the vue instance like this:

    var app = new Vue({
        el: '#root',
        data: {
            url: "{{route('showphoto')}}/{{$photos[0]->id}}"
        }
    });

Then it works! Now I only need to figure out how to iterate to the next image, but that is another question.

Tommy001 started a new conversation Use Vue In Blade To Add A Photo Id After A Route In A Href Link

I have an album with photos in it. When I click on a image in the album it opens in another blade template. I also pass a variable to this "photo blade template" that holds all image id's from the album, to be able to add a button to go to the next image (without having to return to the album and click on the next image there.

I am trying to use Vue.js to accomplish this by adding the next image id (from Vue) at the end of the href link, like this;

<div id="root" class="image"><a v-bind:href="'{{route('showalbum')}}'+/nextPhoto"><img src="{{ asset($photo->main_img) }}"></a></div>

I have only begun building the vue instance, this is what I have now:

    var app = new Vue({
        el: '#root',
        data: {
            nextPhoto: {!! $photos[0]->pluck('id') !!}
        }
    });

nextPhoto is supposed to hold the image id for the next image, but all I get is error messages in the console "Error compiling template", so my question is: what would be the correct syntax for binding in combination with helpers like asset and url?

To clarify, I am not asking about the vue instance, I get that it's terrible at thios point, I only want to figure out the correct syntax in the href link.

24 Mar
2 months ago

Tommy001 left a reply on Need Workaround To Run Composer.

YOU ARE THE BEST! After creating the php alias I mentioned that worked straight away, by adding the composer command after the line you proposed, like this:

php <path to composer>/composer.phar update

Tommy001 started a new conversation Need Workaround To Run Composer.

On my shared hosting it's possible to connect with SSH and install and run composer. I can also run php commands by first saving this alias:

alias php="/usr/local/php72/bin/php"

After that I can use the usual php artisan commands. But now to my question. When I try to run composer update it fails with error messages saying that the CLI php version is 5.6.3. I have asked the support people at my shared hosting, and apparently it's not possible to change the default php version for users, only for sites. So is there a way to run composer programmatically instead, from within the application? Or is there another workaround for this?

12 Mar
3 months ago

Tommy001 left a reply on Which User Permissions Package To Choose?

OK, thanks. In the end I went along with Laratrust, because of the Teams option (which I think might correspond to my needs).

11 Mar
3 months ago

Tommy001 started a new conversation Which User Permissions Package To Choose?

I am building a website where each new user that registers an account, according to a monthly payment plan, should become the "head" for that account and should have the possibility to create new sub accounts for other non-paying users, that are attached to the main account. The head user should also have the possibilty to assign different roles and permissions to the invited fellow members.

The difference between plans should mainly be the allowed number of invitations.

All members in each "group" that consists of one main account and a number of sub accounts should only be able to see theie own content.

I have started looking at different team and user permissions packages, but I would really like to hear what you can recommend. With a bit of luck and advice I could maybe go for the right choice from the beginning.

So which package can you recommend for this application? So far I have looked at Laravel-permission by Spatie Bouncer by Joseph Silber and also santigarcor/laratrust,

I have intermediate skills and would want to keep things as clean and simple as possible.

09 Mar
3 months ago

Tommy001 left a reply on Can't Figure Out Difference Between Local, Stage And Production Site

I finally figured it out... in case anyone else has the same problem. Row 7 of the file /vendor/unisharp/laravel-filemanager/public/js/lfm.js:

var route_prefix = (options && options.prefix) ? options.prefix : '/laravel-filemanager';

In my case I had to change the path to '/mysite/public/laravel-filemanager'. After that it worked :-).

Tommy001 started a new conversation Can't Figure Out Difference Between Local, Stage And Production Site

Using GIT I have built a Laravel site, which among other things uses Laravel File Manager. Locally everything works and when I just transfer ALL files manualy with FileZilla to a folder on my webserver, it also works just fine. All routes that use Laravel Filemanager works fine and there are no problems.

BUT, when I navigate to another folder in my webserver and clone the github repo (which is up-to-date), on the same folder level, everything still works EXCEPT for Laravel Filemanager. When I try to upload an image, for example, I get an "Object not found" and a 404 messsage.

So the only thing that differs is that in the latter case I am using GIT (which is what I want to do, not just keeping track of all changes on my own and transfer files manually). So the conclusion would be that something is left out by .gitignore, that shouldn't. But this is the .gitignore file:

/public/hot
/public/photos
/public/storage
/storage/*.key
/.idea
/.vscode
npm-debug.log
yarn-error.log
.env

I have also cleared routes and config cache whithout any luck. I have spent hours comparing files and folders between the three sites (locally, and the two remote sites) trying to figure out why Laravel Filemanager is not found in just the one using GIT.

I have already posted a similar question on the same topic, but the solution that time was to manually transfer all files to the webserver, and I really need to be able to use git building my laravel sites, so I post the question once more.

Can anyone help?

02 Mar
3 months ago

Tommy001 left a reply on Can't Get Storage::delete() Method To Work

Thanks! That worked straight away. I am learning step by tep :-).

28 Feb
3 months ago

Tommy001 started a new conversation Can't Get Storage::delete() Method To Work

Apart from deleting the row in the images data table I also want to delete the actual files on disk. In my controller I have this in the destroy method:

       $photo = ImageModel::find($id);
       
if(Storage::delete(["public".$photo->main_img, "public".$photo->thumb_img] )){ 
    // public/photos/1/photo.jpg and public/photos/1/thumbs/photo.jpg
       ImageModel::destroy($id);
       $message = 'The photo is deleted';
   }
   else{
       $message = 'The photo could not be deleted';
   }
       return redirect()->route('showalbum', ['id' => $photo->album_id, 'message', $message]);
   }```

Without the if statement the ```Image::destroy($id)``` works as it should. That post in the db table is deleted.
But I can't get the ```Storage::delete()``` method to work.

The photos resides in the main public folder and not in storage/app/public folder. I suppose that might have something to do with it? Although I did create the symlink with ```php artisan storage:link``` command.

I haven't quite understood the symlink part... as you can tell.
28 Jan
4 months ago

Tommy001 left a reply on Laravel Does Not Find File Manager After Move To Webserver

Thanks for your answer. I already had that symbolic link in place, so for example images can be fetched with the helper function asset('storage/images/whatnot.jpg'). But what I need now, if I haven't misunderstood something, is to alter the path to the actual application Laravel Filemanager.

27 Jan
4 months ago

Tommy001 started a new conversation Laravel Does Not Find File Manager After Move To Webserver

I have installed CKEditor and Laravel file manager, wich works fine locally. But after moving the project to a test subfolder in my shared hosting, I get the error message Object not found. I can see that the path to the application is wrong, but where do I change it (to add those extra folders in the path)?

I have tried to change base_directory in the lfm.php file and also the url_prefix in that same file, without luck.

Anyone?

26 Jan
4 months ago

Tommy001 left a reply on Unexpected '?' In Helpers.php On Line 500

Thanks Snapey... that was indeed the problem. php -v givs me PHP 5.6.33 in my cygwin CLI. I will have to post them a question and probably wait until monday for this to be fixed :-/

Tommy001 started a new conversation Unexpected '?' In Helpers.php On Line 500

I have built a Laravel 5.7 site locally and I am now trying to deploy it to a remote shared webserver. I am half way there, but no images are showing though they exist in the right folders and also when I try to run "php artisan config:cache" I get the above error message about a missing '?' in "/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php on line 500".

All the answers I have seen after googling the solution has been that I need PHP7. But the thing is that I do have that. Locally where everyting works I have PHP 7.2.3. and on the remote server I have PHP 7.2.10 (there are 2 more versions to choose from, but the problem is the same for each of these.

What do I do? Maybe I should mention that I haven't got access to composer on the remote server, so I have transferred all vendor files manually with Filezilla.

03 Dec
6 months ago

Tommy001 left a reply on Why Do I Only Get One Child Per Parent?

@CRONIX - OK, thanks again. I will read up on that. I have spent hours and hours installing xdebug and trying to get php-debug work with Atom, and now it finally works. So I will be able to see what actually happens by stepping through the loop and watching the local variables. I will get there somehow.

Tommy001 left a reply on Why Do I Only Get One Child Per Parent?

@CRONIX - Thanks for your answer. I can see that the array gets reset on every loop. But if there are children the function is calling itself recursively and the array will get reset no matter what? I have tried to figure out how to use your suggestion but every time the result is exactly the same – only one child.

I struggle on :-), thanks for helping.

02 Dec
6 months ago

Tommy001 started a new conversation Why Do I Only Get One Child Per Parent?

I am trying to build a genealogy tree from a single persons table containing id, name, mother_id and father_id. The mother_id and father_id points to the persons parents and if these are both null, it means that this person is at the top level in the tree.

I found an answer to a similar question at https://laravel.io/forum/06-27-2014-unlimited-depth-nested-eloquent-collection, and I have adapted the code to almost work as I want. I get the top level persons as expected, but only 1 child for every person that has children.

I have this code so far in my controller:

    public function parenttree()
    {
      $family_id = auth()->user()->family_id;
      $tree = array();
      //GET TOP LEVEL ITEMS
      $top_level = Person::where('family_id', $family_id)
      ->where('mother_id', null)
      ->where('father_id', null)
      ->get();

      foreach($top_level as $top){
        $branch = array();
        $branch['id'] = $top->id;
        $branch['name'] = $top->name;
        $children = Person::where('family_id', $family_id)
        ->where('mother_id', $top->id)
        ->orWhere('father_id', $top->id)
        ->get();
        //CHECK FOR CHILDREN
        if($children->count() > 0) {
            //THERE ARE CHILDREN PASS THEM TO A RECURSIVE FUNCTION TO GET LIST
            $branch['children'] = $this->getChildren($children);
        } else {
            //THERE ARE NO CHILDREN SET TO EMPTY ARRAY
            $branch['children'] = array();
        }
        $tree[] = $branch;
      }

  dd($tree);

        return view('/family/familytree', ['persons'=>$persons]);
    }

    function getChildren($children) {
      $family_id = auth()->user()->family_id;
      foreach($children as $child){
        $child_branch = array();
        $child_branch['id'] = $child->id;
        $child_branch['name'] = $child->name;
        $children = Person::where('family_id', $family_id)
        ->where('mother_id', $child->id)
        ->orWhere('father_id', $child->id)
        ->get();
        //CHECK FOR CHILDREN
        if($children->count() > 0) {
          //THERE ARE CHILDREN PASS THEM TO THIS FUNCTION (RECURSION) TO GET LIST
          $child_branch['children'] = $this->getChildren($children);
      }  else {
          //THERE ARE NO CHILDREN SET TO EMPTY ARRAY
          $child_branch['children'] = array();
        }

        return $child_branch;
      }
    }

And this is how the dd($tree) looks like, There should be more than one child on the last level.

array:5 [▼
  0 => array:3 [▶]
  1 => array:3 [▶]
  2 => array:3 [▼
    "id" => 22
    "name" => "Anders Lindgren"
    "children" => array:3 [▼
      "id" => 12
      "name" => "Maria Lindgren"
      "children" => array:3 [▼
        "id" => 14
        "name" => "David Lindgren"
        "children" => []
      ]
    ]
  ]
  3 => array:3 [▶]
  4 => array:3 [▶]
]
´´´
01 Dec
6 months ago

Tommy001 left a reply on Need Help With Big Query For Family Tree

@KOBEAR - Thanks, I will give that a try. I didn't know that was possible.

26 Nov
6 months ago

Tommy001 left a reply on Need Help With Big Query For Family Tree

@LOSTDREAMER_NL - That sounds like a better way to do it. I will try to figure out how to adapt your example to my use case. Thanks!

Tommy001 started a new conversation Need Help With Big Query For Family Tree

I am trying to build a family tree from a single table persons. I have this SQL query that works fine when I use it directly in phpmyadmin:


fathersfathersmother.name, fathersmothersfather.name, fathersmothersmother.name, mothersfathersfather.name, mothersfathersmother.name, mothersmothersfather.name, 

mothersmothersmother.name FROM (((((((((((((persons 
LEFT JOIN persons AS father ON persons.father_id = father.id) 
LEFT JOIN persons AS mother ON persons.mother_id = mother.id) 
LEFT JOIN persons AS fathersfather ON father.father_id = fathersfather.id) 
LEFT JOIN persons AS fathersmother ON father.mother_id = fathersmother.id) 
LEFT JOIN persons AS mothersfather ON mother.father_id = mothersfather.id) 
LEFT JOIN persons AS mothersmother ON mother.mother_id = mothersmother.id) 
LEFT JOIN persons AS fathersfathersfather ON fathersfather.father_id = fathersfathersfather.id) 
LEFT JOIN persons AS fathersfathersmother ON fathersfather.mother_id = fathersfathersmother.id) 
LEFT JOIN persons AS fathersmothersfather ON fathersmother.father_id = fathersmothersfather.id) 
LEFT JOIN persons AS fathersmothersmother ON fathersmother.mother_id = fathersmothersmother.id) 
LEFT JOIN persons AS mothersfathersfather ON mothersfather.father_id = mothersfathersfather.id) 
LEFT JOIN persons AS mothersfathersmother ON mothersfather.mother_id = mothersfathersmother.id) 
LEFT JOIN persons AS mothersmothersfather ON mothersmother.father_id = mothersmothersfather.id) 
LEFT JOIN persons AS mothersmothersmother ON mothersmother.mother_id = mothersmothersmother.id ORDER BY persons.name;```

Now I am trying to transform that working query into a query that Laravel accepts:

```      $tree = \DB::table('persons')
      ->distinct(['persons.name, father.name, mother.name, fathersfather.name, fathersmother.name, mothersfather.name, mothersmother.name, fathersfathersfather.name, fathersfathersmother.name, fathersmothersfather.name, fathersmothersmother.name, mothersfathersfather.name, mothersfathersmother.name, mothersmothersfather.name, mothersmothersmother.name'])
      ->leftjoin('persons as father','persons.father_id', '=', 'father.id')
      ->leftjoin('persons as mother','persons.mother_id', '=', 'mother.id')
      ->leftjoin('persons as fathersfather','father.father_id', '=', 'fathersfather.id')
      ->leftjoin('persons as fathersmother','mother.mother_id', '=', 'fathersmother.id')
      ->leftjoin('persons as mothersfather','mother.father_id', '=', 'mothersfather.id')
      ->leftjoin('persons as mothersmother','mother.mother_id', '=', 'mothersmother.id')
      ->leftjoin('persons as fathersfathersfather','fathersfather.father_id', '=', 'fathersfathersfather.id')
      ->leftjoin('persons as fathersfathersmother','fathersfather.mother_id', '=', 'fathersfathersmother.id')
      ->leftjoin('persons as fathersmothersfather','fathersmother.father_id', '=', 'fathersmothersfather.id')
      ->leftjoin('persons as fathersmothersmother','fathersmother.mother_id', '=', 'fathersmothersmother.id')
      ->leftjoin('persons as mothersfathersfather','mothersfather.father_id', '=', 'mothersfathersfather.id')
      ->leftjoin('persons as mothersfathersmother','mothersfather.mother_id', '=', 'mothersfathersmother.id')
      ->leftjoin('persons as mothersmothersfather','mothersmother.father_id', '=', 'mothersmothersfather.id')
      ->leftjoin('persons as mothersmothersmother','mothersmother.mother_id', '=', 'mothersmothersmother.id')
      ->where('persons.family_id' ,'=', $family_id)
      ->get();```

But all I get are null values (in all 15 arrays, this is only the first one):
```Collection {#876 ▼
  #items: array:15 [▼
    0 => {#860 ▼
      +"id": null
      +"father_id": null
      +"mother_id": null
      +"user_id": null
      +"family_id": null
      +"name": null
      +"born": null
      +"died": null
      +"image": null
      +"story": null
      +"created_at": null
      +"updated_at": null
      +"gender": null```

Can someone please see what I am doing wrong?
19 Nov
7 months ago

Tommy001 left a reply on Stuck In Learn Vue Step By Step: Episode 6

Thanks! That worked. As far as I remember v-model had not been explained in the previous lessons though. I will read up on that, Thanks again.

Tommy001 started a new conversation Stuck In Learn Vue Step By Step: Episode 6

At the end of episode 6 we are suggested to do some homework, namely to add buttons to a UL list and tick off completed tasks in that list. I got stuck immediately on adding buttons or checkboxes to the UL list of tasks.

Anyone? Is it really possible to add buttons to each list element in a v-for loop?

08 Nov
7 months ago

Tommy001 left a reply on Need Advice On Genealogy Feature In Existing Site

@MARTINBEAN - neo4j really seems to be an interesting database concept to explore, but for now I will go with what jlrdw suggested

Tommy001 left a reply on Need Advice On Genealogy Feature In Existing Site

@39DG - Thanks, yes this seems like a simple enough solution.

Tommy001 left a reply on Need Advice On Genealogy Feature In Existing Site

Thanks a lot jlrdw and siangboon, I will look into your suggestions. I will probably build my own feature.

07 Nov
7 months ago

Tommy001 started a new conversation Need Advice On Genealogy Feature In Existing Site

I am building a site with several different features (recipes, stories, photos ...) but I would also like to add a feature to build a simple family tree. Should I do this from scratch or can anyone suggest a package that I can integrate into my laravel 5.6 site?

18 Aug
10 months ago

Tommy001 left a reply on How To Update Table In Controller Using A Relationship?

Cronix: from the "edit recipe" view I send an array with all ingredients, and I want to update the recipe table with all those ingredients in the foreach loop. Since there will be more fields (coming soon) that is supposed to be saved in the recipe table and I only want to have one "Save changes" in that view, I would really like to also update the ingredients in the recipe controller.

Tommy001 started a new conversation How To Update Table In Controller Using A Relationship?

I have a model called Recipe (table = recipes) and another called Ingredient (table = ingredients). In the Recipe model I have added this relationship, since one recipe has many ingredients:

public function ingredients()
{
  return $this->hasMany('App\Ingredient', 'recipe_id');
}

...and in my RecipeController I have this update function, where I recieve values from an ingredient form:

    public function update(Request $request, $id)
    {
        $recipe = Recipe::find($id);

        $ingredients = $request->all();

        foreach($ingredients as $ingredient){
          $recipe->ingredients()->ingredient = $ingredient[0];
          $recipe->ingredients()->quantity = $ingredient[1];
          $recipe->ingredients()->unit = $ingredient[2];
          $recipe->ingredients()->comment = $ingredient[3];
        }

        $recipe->ingredients()->save();
    }

Above I am attempting to update the values in the ingredients table that belong to the recipe in question. But I get this error message on the last line:

Too few arguments to function Illuminate\Database\Eloquent\Relations\HasOneOrMany::save(), 0 passed in 

So how can I save the updated values from the form?

17 Aug
10 months ago

Tommy001 left a reply on Variable Passed From Serviceprovider Not Available In App.blade.php

Sorry Snapey for not getting back. All help is of course much appreciated. Thanks!

16 Aug
10 months ago

Tommy001 left a reply on Variable Passed From Serviceprovider Not Available In App.blade.php

Oops I didn't see your answer there Cronix beforing posting my solution. Thanks, I will try to use your solution. Sure seems a lot easier!

Tommy001 left a reply on Variable Passed From Serviceprovider Not Available In App.blade.php

Finally got it to work after all with using auth()->user('id') instead of Auth:

    public function boot()
    {
        \View::composer('layouts.app', function($view)
        {
          $user = auth()->user('id');
          $family = Family::where('family_admin', $user['id'])->value('name');
          $view->with('family', $family);
        });
  }

Tommy001 left a reply on Variable Passed From Serviceprovider Not Available In App.blade.php

That was it.. also found another thread with the same problem. Thanks a lot! That was a pitty, I really wanted to pass the family name of the authenticated user to app.blade.php. So I first need the id of the current user and then fetch the family name from another table.

So I will problably have to the the whole thing inside app.blade.php, which is not good practice I believe.

Tommy001 left a reply on Variable Passed From Serviceprovider Not Available In App.blade.php

Turns out nothing gets passed this line ... if (Auth::check()) ... Despite the fact that I did start the project with ...php artisan make:auth... Still trying... This is the whole serviceprovider: ... namespace App\Providers; use Illuminate\Support\ServiceProvider; use App\Family; use Illuminate\Support\Facades\Auth; class PassdataServiceProvider extends ServiceProvider { /** * Bootstrap services. * * @return void */ public function boot() { $user = Auth::user(); if (Auth::check()) { exit; // just to test if we get this far // $family = Family::where('family_admin', Auth::user()->id)->value('name'); View::composer('family', function($view) { return 'Johansson'; }); } } } ...

15 Aug
10 months ago

Tommy001 started a new conversation Variable Passed From Serviceprovider Not Available In App.blade.php

Hi I needed to pass a variable to app.blade.php, so I created a new service provider named PassdataServiceProvider and added this in the boot method:

public function boot()
{
  if (Auth::check())
  {
    // $family = Family::where('family_admin', Auth::user()->id)->value('name');
    View::composer('app', function($view)
    {
      $view->with('family', 'Johansson'); // just changing the variable to a fixed value for testing purposes
    });
  }
}

Then I registered this new provider in config/app.php in the providers array:

    /*
     * Custom Providers...
     */
    App\Providers\PassdataServiceProvider::class,

But the variable $family is not available in app.blade.php. What do I do wrong here?

02 Apr
1 year ago

Tommy001 left a reply on Keep Getting Error MethodNotAllowedHttpException

Found it. In the function I tried to do a redirect back to where I came from in stead of just returning the approriate view. So the message about "method not allowed" probably came from the next step AFTER my upload function. Thanks a lot for your help. I keep learning.

Tommy001 left a reply on Keep Getting Error MethodNotAllowedHttpException

rin4ik; !! I tried your suggestion to clear everything and just dump some text in the function and then it did find this route! So there is something wrong with my code inside the controlelr function. The error message made me think that it must be that the route is not found... One step closer to the solution. Thanks yassiNebel for the tip on clearing things also, I will do that too..

Tommy001 left a reply on Keep Getting Error MethodNotAllowedHttpException

yassiNebel, yes I have done so. No matter what I try I keep getting the Method not allowed error. It really should work now :-|

Tommy001 left a reply on Keep Getting Error MethodNotAllowedHttpException

rin4ik: thanks again, I tried your suggestion to use a named route, but no luck. I must be doing something really stupid, unfortunately I cannot see what it is (spent hours on this now...)

Tommy001 left a reply on Keep Getting Error MethodNotAllowedHttpException

yassiNebel, thanks for the tip on the optional argument in the route. I didn't know about that. Still have to state $id = false in the argument list though? Unfortunately this did not help. Same result.

rin4ik: thanks for the tip but I also have included the csrf token in all forms.

Tommy001 started a new conversation Keep Getting Error MethodNotAllowedHttpException

In order to upload either a new image in a new post or changing image in an old post, I have 2 routes that points to the same controller function in my web.php:

Route::post('/upload/{id}', '[email protected]');
Route::post('/upload', '[email protected]');

I have this in my UploadController:

public function upload($id = false, Request $request){
    // code to upload an image to a new post OR to a post that already exists
}

this is the form action to upload image in a new post (which works fine):

<form class="bild" action="{{ URL::to('upload') }}" method="post" enctype="multipart/form-data">

this is the form action to upload image in an old post (which does not work):

<form class="bild" action="{{ action('[email protected]',$recept->id) }}" method="post" enctype="multipart/form-data">

Whenever I try to use the route upload/{id} i get the error MethodNotAllowedHttpException.

Can anyone see what I am doing wrong?

01 Apr
1 year ago

Tommy001 left a reply on How Can I Expand A Variable Inside Double Curly Braces

Sorry about the noise... I got it:

This works, but if anyone has a better idea, please let me know :-)

Tommy001 started a new conversation How Can I Expand A Variable Inside Double Curly Braces

I have an uploadcontroller for images. When the image is stored with the storage method and also stored in the appropriate db table I redirect back to the view I came from, like this (with the filename stored in the session):

return redirect()->back()->with('bildnamn', $fileNameToStore);

Then, in the view, I want to show the uploaded image, so I fetch it back from the session:

@if (session()->has('bildnamn')) @php $bildnamn = session('bildnamn'); echo $bildnamn; {{-- the image name shows here --}} @endphp {{-- but how can I expand the variable here? --}} @endif

17 Mar
1 year ago

Tommy001 left a reply on Question Regarding Form Request Validation

Thanks all, I am getting to understand how models works now :-).

14 Mar
1 year ago

Tommy001 left a reply on Question Regarding Form Request Validation

OK, thanks tykus and Snapey, I will dig deeper into the documentation to understand what the destroy method means, and yes it seems odd to delete things inside an update function. A separate form also seems to be a way of doing it. I will check out that possibility.

12 Mar
1 year ago

Tommy001 started a new conversation Question Regarding Form Request Validation

I am a total newbie to Laravel, so please bare with me for asking stupid questions. My first problem building a first test site is using the Form Request Validation. I have a controller that builds a couple of forms with this function (where I type-hint the Form Request 'SaveTodoForm)':

 public function update(SaveTodoForm $request, Task $task)
{
    if(isset($_POST['delete'])) {
        $task->delete();
        return redirect('/');
    }
    else
    {
        $task->description = $request->description;
        $task->save();
        return redirect('/');
    }
}

This function is called when a post should be saved or deleted. This worked fine until I added the Form reqest validation. If the user chooses to click on Delete he is redirected to the front page (which indicate failed validation?).

So I added an if statement in the Form request like this (testing if the user clicked delete again):

public function rules()
{
  if(isset($_POST['delete'])) {
    return [];
  }
    return [
        'description' => 'required|max:10',
    ];
}

Then it works fine again. So my 2 questions are ... Why do the request fail even though there is nothing wrong with the post that I try to delete (less than 10 chrs). And second... is this the way to work around this?