samedi 27 mai 2017

Laravel 5 return view not working

I am trying to return a view that is located in a subfolder of views:

enter image description here

I have a route that calls a controller and in the index function it returns the view:

Route:

Route::resource('employee','EmployeeController');

Controller:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request; use App\Employee;

class EmployeeController extends Controller { /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { // return view('employee.index'); }

/**
 * Show the form for creating a new resource.
 *
 * @return \Illuminate\Http\Response
 */
public function create()
{
    //
}

/**
 * Store a newly created resource in storage.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return \Illuminate\Http\Response
 */
public function store(Request $request)
{
    //
}

/**
 * Display the specified resource.
 *
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function show($id)
{
    //
}

/**
 * Show the form for editing the specified resource.
 *
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function edit($id)
{
    //
}

/**
 * Update the specified resource in storage.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function update(Request $request, $id)
{
    //
}

/**
 * Remove the specified resource from storage.
 *
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function destroy($id)
{
    //
}
}

When I try the following url:

http://cats/employee

I get this error message:

Whoops, looks like something went wrong. 1/1 InvalidArgumentException in FileViewFinder.php line 137: View [employee. index] not found.

in FileViewFinder.php line 137
at FileViewFinder->findInPaths('employee. index', array('C:\\inetpub\\vhosts\\cats\\resources\\views')) in FileViewFinder.php line 79
at FileViewFinder->find('employee. index') in Factory.php line 128
at Factory->make('employee. index', array(), array()) in helpers.php line 917
at view('employee. index') in EmployeeController.php line 20
at EmployeeController->index()
at call_user_func_array(array(object(EmployeeController), 'index'), array()) in Controller.php line 55
at Controller->callAction('index', array()) in ControllerDispatcher.php line 44
at ControllerDispatcher->dispatch(object(Route), object(EmployeeController), 'index') in Route.php line 203
at Route->runController() in Route.php line 160
at Route->run() in Router.php line 559
at Router->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 30
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in SubstituteBindings.php line 41
at SubstituteBindings->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in VerifyCsrfToken.php line 65
at VerifyCsrfToken->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in StartSession.php line 64
at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 102
at Pipeline->then(object(Closure)) in Router.php line 561
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 520
at Router->dispatchToRoute(object(Request)) in Router.php line 498
at Router->dispatch(object(Request)) in Kernel.php line 174
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) in Pipeline.php line 30
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in TransformsRequest.php line 30
at TransformsRequest->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in TransformsRequest.php line 30
at TransformsRequest->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in ValidatePostSize.php line 27
at ValidatePostSize->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 46
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 102
at Pipeline->then(object(Closure)) in Kernel.php line 149
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 116
at Kernel->handle(object(Request)) in index.php line 53

It is not understand my code:

return view('employee.index');

Did I make a mistake unknowingly?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2s2cTwH
via IFTTT

laravel 5.4 packages.json invalid

I am running homestead in vagrant on my windows 10 machine for Laravel 5.4. I was following the beginner laracasts (episode 14), which directed me to run npm install. I noticed my output was significantly shorter than the one in the tutorial, only listing

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules/chokidar/node_modules/fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.1: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

Upon further investigation, running npm show gave the error

npm ERR! Invalid package.json npm ERR! A complete log of this run can be found in: npm ERR! /home/vagrant/.npm/_logs/2017-05-27T23_01_22_283Z-debug.log

Here is the log referenced above:

0 info it worked if it ends with ok 1 verbose cli [ '/home/vagrant/.nvm/versions/node/v7.10.0/bin/node', 1 verbose cli '/home/vagrant/.nvm/versions/node/v7.10.0/bin/npm', 1 verbose cli 'show' ] 2 info using npm@4.6.1 3 info using node@v7.10.0 4 verbose stack Error: Invalid package.json 4 verbose stack at /home/vagrant/.nvm/versions/node/v7.10.0/lib/node_modules/npm/lib/view.js:84:30 4 verbose stack at /home/vagrant/.nvm/versions/node/v7.10.0/lib/node_modules/npm/node_modules/read-package-json/read-json.js:356:5 4 verbose stack at checkBinReferences_ (/home/vagrant/.nvm/versions/node/v7.10.0/lib/node_modules/npm/node_modules/read-package-json/read-json.js:320:45) 4 verbose stack at final (/home/vagrant/.nvm/versions/node/v7.10.0/lib/node_modules/npm/node_modules/read-package-json/read-json.js:354:3) 4 verbose stack at then (/home/vagrant/.nvm/versions/node/v7.10.0/lib/node_modules/npm/node_modules/read-package-json/read-json.js:124:5) 4 verbose stack at /home/vagrant/.nvm/versions/node/v7.10.0/lib/node_modules/npm/node_modules/read-package-json/read-json.js:311:12 4 verbose stack at /home/vagrant/.nvm/versions/node/v7.10.0/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:78:16 4 verbose stack at tryToString (fs.js:449:3) 4 verbose stack at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:436:12) 5 verbose cwd /home/vagrant/Code/Circles 6 verbose Linux 4.4.0-66-generic 7 verbose argv "/home/vagrant/.nvm/versions/node/v7.10.0/bin/node" "/home/vagrant/.nvm/versions/node/v7.10.0/bin/npm" "show" 8 verbose node v7.10.0 9 verbose npm v4.6.1 10 error Invalid package.json 11 verbose exit [ 1, true ]

I am no npm expert, but I cannot see any evident issues with the package.json. is one of the dependencies not valid or did I break something?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2rag4EC
via IFTTT

Laravel - How to upload file to a different folder

I'm developing a website that upload file to public/images but in my sharing host i have a different structure so the upload doesn't work well.

My structure is that:

- css
- images(I WANT TO UPLOAD TO THIS FOLDER)
- fonts
- js
- laravel-code
-.htaccess

If i do echo base_path() i get /laravel-code but i need to back and i don't know how.

If use public_path it creates a /public/images inside laravel-code folder and i don't want that.

How can i save images in my images folder?

Thank you



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2rsP0kL
via IFTTT

Laravel dynamically resolve model type from route

Is there a way in Laravel 5.4 that if I pass in from a route the name of an object say product so /api/requests/product or /api/requests/item

The issue is that I can't typehint from the route as my route looks like this:

Route::post('/requests/{type}', 'RequestsController@store');

I thought that I could use a switch case in the store method like so:

 public function store($type)
    {
       switch ($type) {
           case Product::class:
               $model = new Product();
               break;
           case Item::class:
               $model = new Item();
               break;
           default: 
               throw new Exception('Cannot resolve model from request type');
       }

    }

However for a larger application, this would become very clunky. Is there a better way to approach this problem perhaps using reflection or the IoC?

Any help is appreciated.

Thanks



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2s8pnST
via IFTTT

Laravel fresh install and git pull, but get error: Untracked working tree file

I installed a fresh copy of Laravel with:

composer create-project --prefer-dist laravel/laravel:5.2.* mylaravelfolder

Then I want to pull a Laravel project I saved in Bitbucket:

cd mylaravelfolder
git init
git remote add origin http://ift.tt/2r9VQLg
git fetch --all
git pull origin master

I get:

error: Untracked working tree file '.env.example' would be overwritten by merge.

I can see the list of untracked files with:

git status

How can I ignore those files and overwrite them with mylaravelproject.git? I read I could do this but wouldn't git add . mess my mylaravelproject.git on Bitbucket?

git add .
git stash
git pull



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2s8etfU
via IFTTT

How to create link for facebook/twitter button in a Laravel 5 project

This is my code for creating the social link:

`<div class="col-lg-3 social">
      <a href="http://ift.tt/nkGzdY" id="a1"><i class="fa fa-facebook"></i></a>
      <a href="twitter.com/username" id="a2"><i class="fa fa-twitter"></i></a>
      <a href="http://ift.tt/2qukmTu" id="a3"><i class="fa fa-google-plus"></i></a>
</div>`

In normal php or html, we just put links in the href attribute like this above.But in laravel, when i click on the link, it took me to a route. So, if i go to a route then how can i define the facebook url link to that route so that it took me to my facebook account?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2r7EVa3
via IFTTT

Laravel, what can each() function do?

I have no specific work to do, just want to know what each() can do. I have googled, and saw this post: http://ift.tt/2qqq6y4
It says

each is there to perform some operations on all items, that's all there is to it and that is what each is already doing.

What are the operations?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2rKapWq
via IFTTT