12

Using the ember-starter-kit all I had to do was throw the contents of it in the /my_laravel_app/public folder and everything was fine.

Now I am trying to create a project with laravel and ember-cli

I'm a little confused as to how I need to structure my application? In which laravel folder should I be running the ember new my-app command? Furthermore, how can I use apache for testing my ember-cli application instead of using ember server command since I need to test it with my laravel generated apis.

Any help is much appreciated!

user1952811
  • 2,398
  • 6
  • 29
  • 49

3 Answers3

29

Here is one way to do it

Go into your root laravel folder and run the ember new my_app_name

Then go into your my_app_name folder and create a new file build_custom.sh add the following lines to the file

ember build
cp dist/index.html ../app/views/ember.php
cp -r dist/assets ../public/assets

Explanation: the first line builds your ember-cli app and generates all the necessary files in the dist/ folder. The second line copies the index.html file generated to app/views/ folder and renames it ember.php so laravel can recognize it. The last line just copies all the assets into your laravel public folder

You can add the following in your app/routes.php file in laravel to serve your ember app. Make sure it's all the way at the bottom so your other api routes take preference

Route::get('{ember?}', function() {
    return View::make('ember');
})->where('ember', '.*'); 

That should be it, everything should work as intended. Good luck.

Maaz
  • 4,193
  • 6
  • 32
  • 50
  • I am still getting a `UnrecognizedURLError: /ember` when I navigate to `ember` route on my laravel app. This seems to be related to settings the rootUrl of the ember app. – Rajat Jan 06 '16 at 10:55
  • this is not working for me. Nor the ember.php is created neither the assets are moved. Ant help would be highly appreciated. – Nouphal.M Feb 11 '16 at 13:04
  • @Nouphal.M did you try running $ bash build_custom.sh from the my-app-name directory? – Teejten Dec 26 '16 at 18:18
  • Works like a charm. Just need to be careful that these two lines are copying the right files at the right places: `cp dist/index.html ../app/views/ember.php` & `cp -r dist/assets ../public/assets` In my case the assets were getting copied to `/public/assets/assets` folder. And Therefore was giving `UnrecognizedURLError: /ember`. Once I fixed the path. Everything worked fine – Tuhin Paul Apr 05 '18 at 17:44
1

Here is another way to do it:

You can create two separate folders: backend (laravel app) and frontend (ember app) . Let's say, your laravel app is running under 192.168.10.10, you can then proxy your ember app ajax requests using ember-cli command: ember serve --proxy http://192.168.10.10. Using this proxy option, all commands will be passed to ip address, specified with --proxy option - in this case ip address, where laravel app is running (where api is listening).

Michal Gallovic
  • 4,109
  • 2
  • 18
  • 25
0

If you getting UnrecognizedURLError: /ember try to remove welcome route on laravel...

Elib
  • 143
  • 2
  • 7