I recently upgraded to 4.1.26 on my local machine and now it seems that whoops isnt working correctly. All I am getting at the moment is a blank screen with a title as seen below, can anyone tell me why this might be happening?
http://imageshack.com/a/img841/820/tpcm.png
I can't tell what's wrong with your application until you at least enable debugging.
As a first guess though, it might be the new remember_token that was introduced in 4.1.26. A lot of people are having issues adjusting to it.
Have you updated your User model yet? If not, open:
app/models/User.php
and add the following methods:
public function getRememberToken()
{
return $this->remember_token;
}
public function setRememberToken($value)
{
$this->remember_token = $value;
}
public function getRememberTokenName()
{
return 'remember_token';
}
Then, add a new column called remember_token (of type VARCHAR(100), TEXT, or whatever equivalent you want) to your users table. It must be nullable.
Finally, when you're ready to authenticate a user, just add true as the second argument to attempt method.
if (Auth::attempt(array('email' => $email, 'password' => $password), true))
{
// At this point the user is remembered
}
That's it. Hope this solves your issue. Happy coding!
Source: Laravel Upgrade Guide
Related
an app I am creating needs to follow Companies, aside from users. And let the companies have their own activities. How is this configured in Laravel getStream. Seems the feeds are only for user types.
timelineFeed = FeedManager::getNewsFeed($user->id)['timeline'];
$aggregatedTimelineFeed = FeedManager::getNewsFeed($user->id)['timeline_aggregated'];
sample model i have is this:
namespace App;
use Illuminate\Database\Eloquent\Model;
class CompanyPost extends Model
{
use \GetStream\StreamLaravel\Eloquent\ActivityTrait;
public function company()
{
return $this->belongsTo('App\Company', 'company_id', 'id');
}
public function activityVerb()
{
return 'company_post';
}
public function activityActorMethodName()
{
return 'company';
}
}
but i have noticed the feed is still saved on the user activities instead of the company activities.
Thanks in advance guys.
Ian seems to have confused you with me in his link to the Github issue which brought this post to my attention.
The reason this is still showing up on the user feed is that this isn't a configurable option at least on a case by case (or model by model) level. You can override what Stream Laravel uses as the "user feed" in the main configuration but as far as I can tell you are stuck posting to the active logged in user's feed unless you build out the functionality yourself with the Stream-PHP libs and abstain from using the StreamLaravel Activity trait.
You can see here starting at Line: 73 of StreamLaravelManager.php what's happening when an activity is created.
public function activityCreated($instance)
{
$activity = $instance->createActivity();
$feed = $this->getFeed($this->userFeed, $instance->activityActorId());
$feed->addActivity($activity);
}
Unfortunately "$this->userFeed" ultimately is pulled from the configuration file and I don't think there is a way to override it.
Personally, I ran into this when creating "like" functionality. I didn't really want people to have to see what everyone "likes" on their timeline since most of it would be irrelevant and it would get cluttered fast so I ended up not even creating a "like" activity. Instead I'm only added it to a users notification feed when someone likes something of theirs. Of course this may not be desirable for everyone to handle it that way but I noticed you had the "like" activity in your screenshot so I figured I'd mention it.
Good luck on your app!
Our stream-laravel project has some documentation on how to change the model
class Pin extends Eloquent {
use GetStream\StreamLaravel\Eloquent\ActivityTrait;
public function author()
{
return $this->belongsTo('Author');
}
public function activityActorMethodName()
{
return 'author';
}
As far as letting volunteers follow companies and users, we have some documentation in the main README.
(edited to remove my mistaken github reference)
sorry for the late reply. I have managed to follow a company creating
a feed group:
company flat On
and the using sample code below to follow:
$feed = FeedManager::getClient()->feed('timeline', $user->id);
$feed->followFeed('company', $companyId);
Unfollow:
$feed->unfollowFeed('company', $companyId);
Add activity:
$companyFeed = FeedManager::getClient()->feed('company', $company->id);
$companyFeed->addActivity([
"actor" => "App\Company:{$company->id}",
"verb" => "company_post",
"object" => "App\CompanyPost:{$post->id}",
"foreign_id" => "App\CompanyPost:{$post->id}"
]);
I saw in the docs about CodeIgniter:
"you can optionally put the transaction system into "test mode", which
will cause your queries to be rolled back -- even if the queries
produce a valid result. To use test mode simply set the first
parameter in the $this->db->trans_start() function to TRUE"
I understand that able to use transaction (test_mode) to support database fixture for testing insert, update, delete. But it still affects to Database. I set db_debug is TRUE.
Any idea about this problem? Thanks so much.
Example code in my controller:
public function __construct(){
//load database library and model
$this->load->library('database');
$this->load->model('message_mdl');
}
public function do()
{
$data_insert = array('message' => 'hello');
$this->db->trans_start(true);
$this->message_mdl->insert($data_insert);
$this->db->trans_complete();
}
I tried this its not working for me too. I don't know why! I'll trying to find the reason. 'll get back here with proper method. If you find it out pls let me know too.
But I tried the alternate method, its working fine.
public function dothis()
{
$data_insert = array('message' => 'hello');
$this->db->trans_begin(); //Manually start transaction.
$this->message_mdl->insert($data_insert);
$this->db->trans_rollback(); //Rollback
}
Make sure that you don't use $this->db->trans_off(); at all.
I've been looking for the answer for two days and still nothing. I've followed several tutorials where nothing more than just a few config settings are required, but my Laravel 4 app still doesn't want to send an e-mail. It always throws the same Exception and nobody seems to have the answer. It seems that I've tried everything but the working one.
Route::get('/sendemail', function() {
$data['user'] = 'Test User';
Mail::send('email.test', $data, function($m) {
$m->to('myemail#example.com')->subject('Email test');
});
});
But when I'm in the specified route, it always throws the same error:
Argument 1 passed to Swift_Transport_EsmtpTransport::__construct()
must implement interface Swift_Transport_IoBuffer, none given
The config is ok and even changing the driver from 'smtp' to 'mail' in config/mail.php throws also Exception.
Argument 1 passed to Swift_Transport_MailTransport::__construct() must be an instance of Swift_Transport_MailInvoker, none given
I'm stuck in here and I don't know that to do. My composer is up to date and PHP version is 5.4.4.
Any advice will be much appreciated.
Thank you.
You have probably found an answer by now.
But I think you need a second argument for the to.
Try:
$data = array('user' => $user);
Mail::send('email.test', $data, function($message) use ($user)
{
$message->to($user->email, $user->name)->subject('Email Test');
});
I'm using Cakephp and trying to put in a method to make sure our reservation system doesn't let two users book the same appointment. Ex. User 1 opens the appointment, and User 2 opens it simultaneously. User 1 books the appointment. User 2 tries to book it but the system checks and sees it is no longer available.
I imagine this would take place in validation, or in a beforeSave(), but can't figure out how to do it.
Right now I made a function in the model to call from the controller. In the controller I have:
if ($this->Timeslot->checkIfNotAvailable()) {
$this->Session->setFlash('This timeslot is no longer available');
$this->redirect(array('controller' => 'users', 'action' => 'partner_homepage'));
}
and in the model I have this function:
function checkIfNotAvailable($data) {
$this->recursive = -1;
$timeslot = $this->find('all', array(
'conditions' => array(
'Timeslot.id' => $this->data['Timeslot']['id'])
)
);
if ($timeslot['student_id'] == 0) {
//They can reserve it, do not spring a flag
return false;
} else {
//Throw a flag!
return true;
}
}
I think I'm mixed up using custom validation when it's not called for. And it's not working obviously. Any suggestions?
Thanks!
If what you have is working, you can stick with it, you could also try creating a beforeValidate() call back function in your Model.
class YourModel extends AppModel {
function beforeValidate(){
if( !$this->checkIfNotAvailable( $this->data ) ) {
unset($this->data['YourModel']['time_slot']);
}
return true; //this is required, otherwise validation will always fail
}
}
This way you remove the time_slot before it goes to validation and it will drop a validation error at that point, kicking the user back to the edit page and getting them to pick a different time slot, ideally the updated data entry page will no longer have the used time slot available.
I have a function inside of a Helper in Magento that returns whether or not a customer attribute equals one.
Here is my Helper class
class Nie_Nie_Helper_Data extends Mage_Core_Helper_Abstract {
public function isNieAdmin() {
if(Mage::getSingleton('customer/session')->getCustomer()->getNieAdmin() == 1) {
return true;
} else {
return false;
}
}
}
Now when I call this function from a class that extends Mage_Core_Block_Template, everything seems to work fine. However when I try to use this inside one of my controllers, it does not work. In fact when I do Mage::getSingleton('customer/session')->getCustomer()->debug() the only variable that is returned is the website_id.
Does anyone know what I have to do in order to get this to work?
At the time of the controller the session objects are not yet initialised (although the session variable must be) so it returns a blank model. My guess is the website_id is deliberately set in the creation of a customer object to act as a default.
You could access $_SESSION['customer'] directly to find what you need, but that is messy. An alternative would be to do what you want in an event that occurs later.
I hope someone can come up with a better answer than mine.
Ok it looks like I had to load up the session myself. I had to put the following in my functions:
Mage::getSingleton('core/session', array('name' => 'frontend'));
Hope this helps.