laravel-4

Laravel Like Eloquent with array value?

六眼飞鱼酱① 提交于 2019-12-05 07:04:04
问题 How can I do a Like-query, with multiple values to search for? $searchWords = explode(' ', Input::get('search')); Then I get an array of words that were given for the search. How can I pass it in this: $pages = Page::where('content', 'LIKE', '%'.$singleWord.'%')->distinct()->get(); A loop can't work, then it overwrites the $pages always; then it keeps always the latest search: foreach($searchWords as $word){ $pages = Page::where('content', 'LIKE', '%'.$word.'%')->distinct()->get(); } 回答1: A

Laravel 4 Blade Templating Engine with Conditional layout

三世轮回 提交于 2019-12-05 06:28:11
问题 I'm using L4 with Blade. I'd like to be able to conditionally extend a layout. For normal use, I'd like to extend the master layout, and for ajax renders, I'd like to be able to extend the ajax template. I use the following code: @if ( isset($ajax) ) @extends('layouts.ajax') @else @extends('layouts.master') @endif But when the page renders it just prints out @extend('layouts.master'). Does anyone know how to conditionally extend a layout or another? Thanks 回答1: Try on the first line :

Laravel belongsTo Relationship

半世苍凉 提交于 2019-12-05 05:53:52
Ok, I am a little confused with the belongsTo relationship for Models. I have a Feeds model that extends Eloguent. I have created a relationship function called User. public function user(){ return $this->belongsTo('User'); // and I also tried return $this->belongsTo('User', 'user_id'); } On the view I am trying to do : @foreach($feeds as $feed) {{$feed->user()->first_name}} {{$feed->user()->last_name}} @endforeach but I am getting this error Undefined property: Illuminate\Database\Eloquent\Relations\BelongsTo::$last_name When I do $feed->user->first_name it works fine, but I thought user()-

Laravel 5 - View [home] not found

岁酱吖の 提交于 2019-12-05 05:52:32
I ran composer update and now I'm running into an issue. I'm getting this error when I'm trying to load my home view: InvalidArgumentException in FileViewFinder.php line 140: View [home] not found. Yes, files exists in my directory (resources/views, etc.). Name is home.blade.php . My controller: <?php namespace Hulahoop\Http\Controllers; use Hulahoop\Http\Requests; use Hulahoop\Http\Controllers\Controller; use Illuminate\Http\Request; class HomeController extends Controller { /** * Display a listing of the resource. * * @return Response */ public function index() { return view('home'); } }

Laravel 4, Composer and hybridauth - How to load additional providers

痞子三分冷 提交于 2019-12-05 05:39:04
I'm using Laravel 4 and have loaded hybridauth via composer and got it working just fine with Facebook and Twitter. Now i'm trying to get it working with Steam, which is listed as an additional provider, however I keep getting the following error: require_once(vendor/hybridauth/hybridauth/hybridauth/Hybrid/Providers/Steam.php) [function.require-once]: failed to open stream: No such file or directory Clearly it's looking in the wrong place, the actual class resides in this location: vendor/hybridauth/hybridauth/additional-providers/hybridauth-steam/Providers/Steam.php There's very little

Does Eloquent relation sync also remove?

邮差的信 提交于 2019-12-05 05:23:04
When updating a model and I sync a relationship, if I don't pass in all the ids that already exist, will that relationship be removed? You decide: sync has 2nd parameter that defaults to true and is responsible for detaching: $model->relationship()->sync([1,2,3]); $model->relationship()->sync([4,5,6]); // attached [4,5,6], detached [1,2,3] $model->relationship()->getRelatedIds(); // [4,5,6] // but: $model->relationship()->sync([4,5,6], false); // attached [4,5,6], detached [] $model->relationship()->getRelatedIds(); // [1,2,3,4,5,6] The answer is Yes it does. I could not find any documentation

How to use Illuminate Database Query Builder & Eloquent in other framework with PHP 5.3.x

淺唱寂寞╮ 提交于 2019-12-05 05:02:04
问题 I did a couple of projects with Laravel in the past but now I need something very light for a project and went to use Slim, it works great for what I need and I want the great Eloquent ORM and Query Builder of Laravel, can't go without it now :) Now I manage to get it all working with composer, using the information that Taylor displayed on his GitHub, copied his piece of code use Illuminate\Database\Capsule\Manager as Capsule; $capsule = new Capsule; $capsule->addConnection([ 'driver' =>

Laravel 4 and Angular JS and Twitter Bootstrap 3 Pagination

大城市里の小女人 提交于 2019-12-05 04:56:52
问题 Edit: I need a pagination in my Laravel 4 - Angular JS application which is structured using twitter bootstrap 3. You may suggest the angularui-bootstrap pagination. But I am not planning to use this right now. I need to explore and utilize the features of Laravel pagination with angular.js. I have seen one blog article here which describe the same. But my bad luck, it is not working and there is a lot of mistakes in the article. So based on that article, I have a Laravel controller function

Laravel 4 - Hashing same password gives different values

独自空忆成欢 提交于 2019-12-05 04:31:40
I am trying to authenticate a user using the Auth::attempt() method and it keeps failing, so I eventually ended up with the following code: $arr = array(); $arr['verified'] = Hash::make('1234') . ' ; ' . Hash::make('1234'); return json_encode($arr); and this is the result: {"verified":"$2y$10$V4yXBUcxealfLrzOE\/xAD.sJ8qpNhrMA6K6dENBBXYqaVx1zSETgy ; $2y$10$C9xpOWLTUyfy1KL.Y3Tot.KWADmQYFK\/HAf6uZGGXTKcVh52qHS4m"} As you can see, the first hash gives $2y$10$V4yXBUcxealfLrzOE\/xAD.sJ8qpNhrMA6K6dENBBXYqaVx1zSETgy and the second hash gives $2y$10$C9xpOWLTUyfy1KL.Y3Tot.KWADmQYFK\

Laravel 4 - understanding View::share()

跟風遠走 提交于 2019-12-05 04:03:25
From what I understand: View::share('foo','bar'); Will make $foo available in all views. However, is it correct to say View::share() can be used only in the __construct() ? Because from outside __construct() I can't make it to work. View::share should be available anywhere within your application. A common place that it is used is in view composers, but it should be usable within a route or wherever you need it. Yes, adding: View::share('foo','bar'); in your routes.php file will make $foo (with a value of 'bar') available in all views. This is especially useful for something like Twitter