laravel-4

Laravel 4 Auth:attempt not working

為{幸葍}努か 提交于 2019-12-04 04:53:48
I am having hard time working with Laravel 4 Auth::attempt method , followed the right documentation, read couple of SO threads but still i am not able to get it working. $userData = array('email' => 'admin@admin.com','password' => 'admin'); if(Auth::attempt($userData)){ // redirect } else{ echo 'Invalid'; } And it returns Invalid everytime Now i am not sure what is the actual reason. In my config/auth.php i have following <?php return array( /* |-------------------------------------------------------------------------- | Default Authentication Driver |-----------------------------------------

Laravel 4 - Return the id of the current insert

心已入冬 提交于 2019-12-04 04:39:57
I have the following query public static function createConversation( $toUserId ) { $now = date('Y-m-d H:i:s'); $currentId = Auth::user()->id; $results = DB::table('pm_conversations')->insert( array( 'user_one' => $currentId, 'user_two' => $toUserId, 'ip' => Request::getClientIp(), 'time' => $now ) ); return $results; } How would i return the id of the row just inserted? Cheers, Instead of doing a raw query, why not create a model... Call it Conversation, or whatever... And then you can just do.... $result = Conversation::create(array( 'user_one' => $currentId, 'user_two' => $toUserId, 'ip' =>

prepared statement with Eloquent ORM / laravel

好久不见. 提交于 2019-12-04 04:32:40
问题 I'm new to laravel and use this as a input query: DB::table('user_input')->insert(array( array('fname' => Input::get('Name'),'lname' => 'no','email' => Input::get('E-Mail'),'date_from' => $from_date,'date_to' => $to_date,'phone' => Input::get('Phone'),'message' => Input::get('Message'),'ip_address' => Request::getClientIp(), 'newsletter' => Input::get('Sign-up')) )); which I would never do like that in standard php, as the query doesn't seem to be prepared and I put user input directly into

Sessions not persisting in Lumen PHP framework

十年热恋 提交于 2019-12-04 04:05:12
I'm using the Lumen (by Laravel) micro-framework for a project, and I'm having some trouble with sessions. I'm just testing the implementation now, but the problem I'm experiencing is that when I set a session variable and then refresh the page, the variable is no longer set. In my .env file I have: SESSION_DRIVER=cookie And I know that this is being picked up, because when I change it to memcached it throws an error (because I don't have memcached set up). I've enabled the middleware too: $app->middleware([ 'Illuminate\Session\Middleware\StartSession', 'Illuminate\View\Middleware

Laravel MySQL how to order results in the same order as in whereIn clause

☆樱花仙子☆ 提交于 2019-12-04 03:36:56
I have two queries, the first one gives me an array of ids, that is in a specific order. Then that array of ids I pass it to the second query like so: Operation::whereIn('id', $ids)->get(); But when I output the result of that query, the order has changed, if the array $ids was something like (4,2,6,9) which is the order I wanted the results to be in, the output will give me 2,4,6,9. How can I avoid that? MySQL way of sorting with order same as in where in clause: $ids; // array of ids $placeholders = implode(',',array_fill(0, count($ids), '?')); // string for the query Operation::whereIn('id'

Laravel 4 query builder - with complicated left joins

我的梦境 提交于 2019-12-04 03:29:58
I'm new to Laravel 4. I have this query: SELECT a.id, active, name, email, img_location, IFNULL(b.Total, 0) AS LeadTotal, IFNULL(c.Total, 0) AS InventoryTotal FROM users AS a LEFT JOIN ( SELECT user_id, count(*) as Total FROM lead_user GROUP BY user_id ) AS b ON a.id = b.user_id LEFT JOIN ( SELECT user_id, count(*) as Total FROM user_inventory GROUP BY user_id ) AS c ON a.id = c.user_id WHERE a.is_deleted = 0 How can I convert it to Laravel query builder? I'm confused on how to use the Laravel join query builder with this type of query. Answer!! Will all the help of petkostas on laravel forum.

Laravel save one to many relationship

自作多情 提交于 2019-12-04 03:19:35
I have the following relationships set up in Laravel: OrderStatus Model - hasMany('Order') Order Model - 'belongsTo('OrderStatus'); The database is set up with an orders table and an order_statuses table. The orders table has a field for order_status_id . When I save an Order, I manually set the order_status_id by fetching the appropriate Order Status model, like this: $status = OrderStatus::where(['name'=>'sample_status'])->firstOrFail(); $order->order_status_id = $status->id; $order->save(); I'm wondering if there is a built in function to do this rather than setting the order_status_id

Generating url relative to the base url in laravel 4

这一生的挚爱 提交于 2019-12-04 03:03:57
I'm new to Laravel & right now building one application on L-4 but got stuck at one place. Can't able to understand how to generate url relative to base url. In laravel-3 i know this can be done by $url = URL::to('user/profile'); But, in L-4 how we can do this.. ? To generate a relative URL, you can use URL::route or URL::action as they allow to pass a $absolute parameter which defaults to true . So to get a relative URL when using named routes for example, you can use the following: URL::route('foobar', array(), false) This will generate a URL like /foobar . deepika jain First you need to

Changing Laravel Blade Delimiter

别说谁变了你拦得住时间么 提交于 2019-12-04 03:02:22
I know that you can change the default blade delimiter using Blade::setEscapedContentTags('[[', ']]'); Blade::setContentTags('[[[', ']]]'); However I don't know where should I put it so that it only affect single blade template as opposed to putting it at app/start/global.php which affect whole application. If you only want to use different tags for a single view, you can set the tags in the closure or controller action that will generate the view. Route::get('/', function() { Blade::setEscapedContentTags('[[', ']]'); Blade::setContentTags('[[[', ']]]'); return View::make('home'); }); This

Laravel unit testing emails

淺唱寂寞╮ 提交于 2019-12-04 03:01:37
My system sends a couple of important emails. What is the best way to unit test that? I see you can put it in pretend mode and it goes in the log. Is there something to check that? There are two options. Option 1 - Mock the mail facade to test the mail is being sent. Something like this would work: $mock = Mockery::mock('Swift_Mailer'); $this->app['mailer']->setSwiftMailer($mock); $mock->shouldReceive('send')->once() ->andReturnUsing(function($msg) { $this->assertEquals('My subject', $msg->getSubject()); $this->assertEquals('foo@bar.com', $msg->getTo()); $this->assertContains('Some string',