I am wanting to give the user an option to delete their current logo and replace it with a new one. Currently I am using Stapler, a Laravel package.
I initially had trouble adding the logo, by means of, I had to create the table entity by adding the logo first, and then updating the other fields:
$company = Company::create(['logo' => Input::file('logo')]);
$company->save();
$companyID = $company->id;
$company = Company::find($companyID);
$company->company_name = Input::get('company_name');
Now, should a user have selected a new logo to add, I want it to clear the current logo and add the new one. I am struggling on how to add the logo into the same company, as on the code above, the Company::create creates a new Company record.
Current code:
Even if I try and dd() the file directly, it returns NULL. Its as if it can't even find it within the view!
$logo = Input::file('logo');
if($logo !== null)
{
$company->logo->clear();
$company->logo = Input::file('logo');;
}
Thank you in advance.
The form wasn't allowing file uploads. By adding:
'files'=>'true'
into the Form::open(array( it added the file.
Related
I'm building a Laravel 9x application where i will need to populate some pages with the google places API.
Reading at the ToS of Google Places, i can only store in my db, for at most 30 days, the place_id.
Now, I'm facing an issue; I have a restaurants.index blade page where I'm showing in a table all the records from the restaurants table.
The issue is that i need to show in each table row the name of the restaurant that i don't have in my db table but i need to fetch it from Google Places Api.
So far, in my RestaurantsController I have done the following :
public function index()
{
$getAllRecords = Restaurant::all();
$google_places_api = new PlacesApi(env('GOOGLE_MAPS_API_KEY'));
$restaurants = new Collection();
foreach($getAllRecords as $restaurant){
$response= $google_places_api->placeDetails($restaurant->google_place_id);
$restaurant['name'] = $response['result']['name'];
$restaurants->prepend($restaurant);
}
dd($restaurants);//When dd here, the collection shows correctly the added value.
$restaurants->paginate(8);
$categories = Category::where('type', 'Restaurant')->cursor();
return view('tenant.restaurants.index', compact('categories', 'restaurants'));
}
And it seems to work pretty well if I dd($restaurants) inside the RestaurantsController as you can see from the picture below :
But when i try to #dd($restaurants) from the restaurants.index page, the added name is completely disappeared as you can see from the picture below :
It's now about a whole day that I'm tryng to understand why this behavior happen, is there anybody who has an idea of what is happening?
Thank you
I am currently working with the Pods plugin.
I extended the user pod and I added a corporate image field.
On the administration everything is fine, I can change the image of each user.
AND :
My problem is that I can not display this image on a front office page..
If i do this : var_dump($pod->field('image_societe'));
It return false, while the field name is correct, and for plain text fields, it works.
But i can do this :
var_dump($pod->fields('image_societe'));
This will return me full of information, but I do not have access to the id of the image, it is not present in the information.
I would like to finally be able to do this:
the_attachment_link( 11923 );
Where 11923 is the image's ID.
To be dynamic according to the user, the documentation says that it must be done like this:
the_attachment_link($pod->field('image_societe.ID'));
But as pods return me false, it does not work.
Does someone have an idea ?
Thank you !
Usually you can get the image url by querying $pod->field('image_societe.guid'). E.g. :
$items = pods('your_pod', array("limit" => -1));
while($items->fetch()) {
echo $items->field('image_societe.guid');
}
If $pod->field('image_societe'); doesn't return anything, then something might be wrong with your pod query, or caching kicking in. So more code would be needed to review this.
I am beginner in SocialEngine and I want to know if there is any way to get the photo of the object in the widget.
Like i know we can get the photo of the object in view using following code.
//in controller
$table = Engine_Api::_()->getDbTable("mytable","module");
$select = $table->select()->where->("table_id", 1);
$fetch = $table->fetchRow($select);
$this->view->fetch = $fetch;
//in view
echo $this->itemPhoto($this->fetch, "thumb.normal");
above line would product the image if there is any otherwise will load the default image.
But this line of code is not working in widget.
I really appreciate your help.
You need to make sure that first param you're passing to $this->itemPhoto is a User instance:
$this->itemPhoto($user, 'thumb.normal', $user->getTitle())
Seems that in your case $this->fetch is simply a Row. You can create user using this code: Engine_Api::_()->getItem('user', $user_id);. Hope this helps.
We need to update finalUrls of all the ads we have. We have several hundred ImageAd and ResponsiveDisplayAds and we don't want to lose the existing configuration and/or images. As Google doesn't allow us to update any property of a AdGroupAd apart from status, we will have to clone them using ADD operator.
While doing this we get several errors and all of them are related to ad.image. What's the correct/best way to go about these updates?
[AdError.IMAGE_ERROR # operations[0].operand.ad]
Firstly, I found out from little googling that adToCopyImageFrom is what I had to use in order to copy over image properties of an ad (ImageAd only!) in order to clone. So, if $currentAd is the AdGroupAd object containing your existing ImageAd and you are trying to create a new one $newAd and want to copy over images, here is what you can do (not sure if this is the best way but worked well for me!):
$newAd = new ImageAd();
$newAd = $ad->ad;
// Let Google do the image copying
// Remember $currentAd is a AdGroupAd and not an Ad
$newAd->adToCopyImageFrom = $currentAd->ad->id;
$newAd->id = null;
$newAd->image = null;
Similarly, for ResponsiveDisplayAd, here is what I did:
$newRespAd = new ResponsiveDisplayAd();
// Make sure you included MediaId while fetching
// $currentRespAd
$newRespAd = $currentRespAd->ad;
$newRespAd->id = null;
Going a bit mad here... :)
I'm just trying to add CCK fields from a Content Profile content type into page-user.tpl.php (I'm creating a highly-themed user profile page).
There seem to be two methods, both of which have a unique disadvantage that I can't seem to overcome:
'$content profile' method.
$var = $content_profile->get_variables('profile');
print $var['field_last_name'][0]['safe'];
This is great, except I can't seem to pass the currently viewed user into $content_profile, and it therefore always shows the logged in user.
'$content profile load' method.
$account_id = arg(1);
$account = user_load($account_id);
$user_id = $account->uid;
$var = content_profile_load('profile', $user_id);
print $var->field_first_name[0]['value'];
Fine, but now I can't access the full rendered fields, only the plain values (i.e. if the field has paragraphs they won't show up).
How can I have both things at once? In other words how can I show fields relating to the currently viewed user that are also rendered (the 'safe' format in 1)?
I've Googled and Googled and I just end up going round in circles. :(
Cheers,
James
Your content profile load method seems to be the closest to what you want.
In your example:
$account_id = arg(1);
$account = user_load($account_id);
$user_id = $account->uid;
$var = content_profile_load('profile', $user_id);
print $var->field_first_name[0]['value'];
The $var is just a node object. You can get the "full rendered fields" in a number of ways (assuming you mean your field with a filter applied).
The most important thing to check is that you're field is actually configured properly.
Go to:
admin/content/node-type/[node-type]/fields/field_[field-name] to configure your field and make sure that under text processing that you've got "Filtered text" selected.
If that doesn't fix it,try applying this:
content_view_field(content_fields("field_last_name"), $var, FALSE, FALSE)
(more info on this here: http://www.trevorsimonton.com/blog/cck-field-render-node-formatter-format-output-print-echo )
in place of this:
print $var->field_first_name[0]['value'];
if none of that helps... try out some of the things i've got on my blog about this very problem:
http://www.trevorsimonton.com/blog/print-filtered-text-body-input-format-text-processing-node-template-field-php-drupal
When you're creating a user profile page there is a built in mechanism for it. just create a user template file, user_profile.tpl.php.
When you use the built in mechanism you automatically get access to the $account object of the user you are browsing, including all user profile cck fields. You have the fields you are looking for without having to programmatically load the user.
I have a field called profile_bio and am able to spit out any mark up that is in without ever having to ask for the $account.
<?php if ($account->content[Profile][profile_bio]['#value']) print "<h3>Bio</h3>".$account->content[Profile][profile_bio]['#value']; ?>
I've tried themeing content profiles by displaying profile node fields through the userpage before and it always seems a little "hacky" to me. What I've grown quite fond of is simply going to the content profile settings page for that node type and setting the display to "Display the full content". This is fine and dandy except for the stupid markup like the node type name that content profile injects.
a solution for that is to add a preprocess function for the content profile template. one that will unset the $title and remove the node-type name that appears on the profile normally.
function mymodule_preprocess_content_profile_display_view(&$variables) {
if ($variables['type'] == 'nodetypename') {
unset($variables['title']);
}
}
A function similar to this should do the trick. Now to theme user profiles you can simply theme your profile nodes as normal.