last day (15 days later) » 

3:39 PM
0
A: check if value is null laravel 5

HicaskYou can use Validation of Laravel with a bit of laravel magic to check if email is not null, try this: public function updatePerfil() { $profileData = Input::except('_token'); $validation = Validator::make($profileData, User::$profileData); if ($validation->passes()) { $updat...

 
thereby giving conflicting with "getClientOriginalExtension()"
 
Updated, try the new code.
 
doesn't work...i need try other way
 
Any error??? You are getting the same conflict getClientOriginalExtension()?
 
yes i want. I dont understand why
 
3:39 PM
imagem must be a file, not an array of files
 
are saying to take the picture in my array?
 
Imagem field must be a single field, eg: <input type="file" name="imagem" /> copy and paste your form or the request body to see what your are sending.
 
i edit my post...u can already see the form
 
everything look ok
can u post your request?? $request->all()
 
give me one second for to redesign the code with which you sent me
give me one error
"Call to undefined method Illuminate\Support\Facades\Request::except()"
 
3:50 PM
can u post your complete controller?? or the complete method?? you must inject in your method Request $request
dont forget to include the namesapce use Illuminate\Http\Request;
 
my namespace and use for controllor
namespace App\Http\Controllers;

use Input;
use Auth;
use Illuminate\Support\Facades\Request;
use Hash;
use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
use HTML;
use Redirect;
use Session;
use Image;
use App\RedesSociais;
 
add use Illuminate\Http\Request
 
give one second i am correct errors
my genre not working...but I guess I was not working last time because of the Request
the date of birthday and genre not working otherwise I think it's all right
 
why not working??
dont forget, date must be 'Y-m-d' format
 
4:06 PM
my form is right
my name in form is data_nascimento and my $rules 'data_nascimento' => 'date',
my $update = $request->only('name','data_nascimento','genero');
the name is working and data_nascimento and genero no
not update
 
what is the name of each field in the model
genero or gender??
each field must be in fillable inside de model
 
{"name":"Jos\u00e9 Cerejo","data_nascimento":"1990-02-25","genero":"Feminino"}
it will reportedly direct the db but not updated these two fields
genero and data_nascimento
u are my hero XD
protected $fillable = ['name', 'email', 'password', 'acesso','genero','data_nascimento'];
 
hahahaha
u got it??
work?
 
i han no genero and data_nascimento
one second i will check
 
are u sure this fields has the same name in database?
genero and data_nascimiento??
 
4:12 PM
yes
one error only
 
??
 
for example if I want to update the image and data_nascimento not work both together
 
ooohhhh
are u using the same code that I post before?
hhahaha sorry u need to update the code
 
I'm working on xampp it updates the db but when I refresh the page have not updated to refresh again
 
check my code
$update = $request->only('name','data_nascimiento');
here I am taking only name and data_nascimiento for update
 
4:15 PM
the code is right
I just have to do the resize again.
But it's strange when I update the image automatically updated in the profile but the other fields need to refresh again
 
??? the code is working now?
 
this line updated so these three fields right?
for example
if I update these three over the image field when updating the image does not appear so soon when you refresh right?
 
yes
you are getting the same error??
update your rules
$rules = [
'email' => 'sometimes|required|email|unique:users',
'name' => 'required|min:5|max:25',
'data_nascimento' => 'required|date',
'imagem' => 'sometimes|required|image|max:1000|mimes:jpeg,jpg,png',
'id'=>'required|integer'
];
 
everything properly updated in the database.
The error is only in refresh the page do not immediately appear the name, the date data_nascimento. I have to make a refresh again
sometimes what is it?
 
u need to refresh the page 2 times?
or only one time?
sometimes is a conditional, if the field exist in request then use all the other rules
hahaha soo strange, if the fields is updated correctly, when u refresh the page one time
everything should appear
 
4:26 PM
2 times...sometimes in one. Is weird. Should the server do not know
already put the resize function :)
thanks
I can take another doubts?
 
hahaha soo strange
the server is crazy?? hahaha
Anything u need, I am here, good look
 
only xampp xD
I created a related table with the users table
public function up()
{
Schema::create('RedesSociais', function(Blueprint $table)
{
$table->increments('id');
$table->integer('id_user')->unsigned();
$table->foreign('id_user')->references('id')->on('users');
$table->string('facebook');
$table->string('twitter');
$table->string('google');
$table->string('linkedin');
$table->string('behance');
$table->timestamps();
});
}
And I want to upgrade but I think not updated because it is not fetching the user_id
 
U want to insert a new record in this table??
 
{"id":"1","facebook":"","twitter":"","google":"","linkedin":"https:\/\/www.linke‌​din.com\/in\/cerejo","behance":""}
yes
public function updateSocial() {
$data['id'] = Auth::user()->id;
$redesociais = Input::except('_token');
$validation = Validator::make($redesociais, RedesSociais::$redesociais);
if ($validation->passes()) {
RedesSociais::where($data, Input::get('id'))->update($redesociais);
return $redesociais;
Session::flash('redes_sociais', 'Redes sociais editadas com sucesso');
return Redirect::to('backend/perfil/redes_sociais');
} else {
return Redirect::to('backend/perfil/redes_sociais')->withInput()->withErrors($validation);
 
but you are updating in base of $redesociais
and in this array the field 'user_id' does not exist
add user_id to $redesociais
$redesocias['user_id']=Auth::user()->id
 
4:35 PM
public static $redesociais = array(
'facebook' => 'active_url',
'linkedin' => 'required',
'twitter' => 'active_url',
'google' => 'active_url',
'behance' => 'active_url',
'id_user' => 'integer',
);
 
jeje no that is the rules of validation
public function updateSocial() {
$redesociais = Input::except('_token');
$redesociais['user_id']=Auth::user()->id;
$validation = Validator::make($redesociais, RedesSociais::$redesociais);
if ($validation->passes()) {
RedesSociais::where($data, Input::get('id'))->update($redesociais);
return $redesociais;
Session::flash('redes_sociais', 'Redes sociais editadas com sucesso');
return Redirect::to('backend/perfil/redes_sociais');
} else {
return Redirect::to('backend/perfil/redes_sociais')->withInput()->withErrors($validation);
copy this code instead
 
yes
{"id":"1","facebook":"","twitter":"","google":"","linkedin":"https:\/\/www.linke‌​din.com\/in\/cerejo","behance":"","id_user":1}
 
now work??
 
no
not fit into the db
in my db i need the fields create_at and update_at?
timestamp
 
not fit??? there is an error in query?
user with id = 1 exist??
in table RedesSociais exist and register with id = 1
?
 
4:44 PM
the table redessociais is still empty
but users table de id = 1 is me
i need insert
 
ahh yes u need insert
 
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1' for key 'PRIMARY' (SQL: insert into redessociais (id, facebook, twitter, google, linkedin, behance, id_user) values (1, , , , linkedin.com/in/cerejo, , 1))
i change here
RedesSociais::where($data, Input::get('id'))->update($redesociais);
for insert
 
what is id???
where is this field?
u need to verify
if($register = RedesSociais::find(Input::get('id'))->first()){
$register->update($redesociais);
}else{
$register = RedesSocias::insert($redesociais);
}
id is the same as user_id in your request?
 
how it works
public function updateSocial() {
$redesociais = Input::except('_token');
$validation = Validator::make($redesociais, RedesSociais::$redesociais);
if ($validation->passes()) {
$user = User::find(Auth::user()->id);
$user = RedesSociais::where($redesociais, Input::get('id'))->insert($redesociais);
return $redesociais;
Session::flash('redes_sociais', 'Redes sociais editadas com sucesso');
return Redirect::to('backend/perfil/redes_sociais');
} else {
return Redirect::to('backend/perfil/redes_sociais')->withInput()->withErrors($validation);
but i will update for your code one second
because i need insert and update
 
ok but we need to know what is id??
{"id":"1","facebook":"","twitter":"","google":"","linkedin":"https:\/\/www.linke‌​‌​din.com\/in\/cerejo","behance":"","id_user":1}
in this id what is ??? the id of the record inside RedesSociais??
I think tha only exist one record per use in the table RedesSociais
correct?
 
4:52 PM
id is primary key in the table redessociais
id_user is the table users
 
only exist one record per use in the table RedesSociais
?
 
yes
 
ok in that case use this instead:
public function updateSocial() {
$redesociais = Input::except('_token');
$redesociais['user_id']=Auth::user()->id;
$validation = Validator::make($redesociais, RedesSociais::$redesociais);
if ($validation->passes()) {
RedesSociais::where('user_id',Auth::user()->id)->update($redesociais);
return $redesociais;
Session::flash('redes_sociais', 'Redes sociais editadas com sucesso');
return Redirect::to('backend/perfil/redes_sociais');
} else {
return Redirect::to('backend/perfil/redes_sociais')->withInput()->withErrors($validation);
work??
I will back
 
exist Validation specifies for URL already pre-defined in laravel?
yes :)
i will do the insert
because when registering is not necessary to have social networks so always need an insert event has no social network
sorry if there were some things do not notice because my English is not very good and I have difficulty understanding the times
 
 
2 hours later…
6:58 PM
Hi, I am here
 
hi :)
I had to go the lessons here to anything caught in the new work...10 minutes
 
haha ok
 
I'm ready to start an evening of 5pm on laravel xD
I was over at least for the place where we left
public function updateSocial() {
$redesociais = Input::except('_token');
$redesociais['id_user']=Auth::user()->id;
$validation = Validator::make($redesociais, RedesSociais::$redesociais);
if ($validation->passes()) {

if($user = RedesSociais::find('id_user',Input::get('id'))->first()){
$user->update($redesociais);
}else{
$user = RedesSocias::insert($redesociais);
}
Session::flash('redes_sociais', 'Redes sociais editadas com sucesso');
return Redirect::to('backend/perfil/redes_sociais');
} else {
i will see the errors
public function updateSocial() {
$redesociais = Input::except('_token');
$redesociais['id_user'] = Auth::user()->id;
$validation = Validator::make($redesociais, RedesSociais::$redesociais);
if ($validation->passes()) {
if($user = RedesSociais::find(Input::get('id'))) {
$user -> update($redesociais);
}else{
$user = RedesSociais::insert($redesociais);
}
Session::flash('redes_sociais', 'Redes sociais editadas com sucesso');
return Redirect::to('backend/perfil/redes_sociais');
} else {
return Redirect::to('backend/perfil/redes_sociais')->withInput()->withErrors($validation);
without erros :D
 
7:19 PM
finally work??
everything ok ??
 
yes
Textos completos
id
id_user
facebook
twitter
google
linkedin
behance
created_at
updated_at

Edita Edita
Copiar Copiar
Apagar Apagar
1
1
https://www.linkedin.com/in/cerejo
0000-00-00 00:00:00
2015-11-17 16:58:56

Edita Edita
Copiar Copiar
Apagar Apagar
2
2
https://www.linkedin.com/in/sdfadsfasd
0000-00-00 00:00:00
0000-00-00 00:00:00
i can remove created_at?
 
This is in base of your model
you have activated timestamps??
 
yes
but i don't need timestamps
is only for select data
 
just disabled it
 
for example to get to the table user name i write
Auth::user()->name and appear
in my table redessociais
is
Auth::RedesSociais()->linkedin
?
my class name is RedesSociais
 
7:24 PM
no
u need to declare the relation inside User model
 
how
 
u need to declare relation of one to many
what is the namespace of your models??
 
App
 
ok u need to declar the relation like this
 
my class extends Model
 
7:27 PM
this method inside the User model
public function redessociais(){
return $this->hasMany('App\RedesSociais','user_id','id');
}
so with this method u can call for each user instance
for example
Auth::user()->redessociais;
this will return all the redessociais of the actual logged user
if u want only the first redessociais
use Auth::user()->redessociais()->first();
and this return only the first redessociais record of the user
 
hummm then I will never be able to write Auth::redessociais
i need create always one function in my user model?
because I have a related table right?
 
yes
is imposible use Auth::redessociais directly
 
ok thanks
Auth::user()->redessociais()->linkedin()
for now
don't apppear
 
noo
Auth::user()->redessociais()->first()->linkedin
the correct way
becaso redessociais return an array
if u take the first
then u take 1 redessociais
 
ahhhhh after the application is easier :)
well my profile page is made
I will start entering projects
thanks a lot for help me
 
7:40 PM
you are welcome
dont forget to accept my answer as correct
please
 
already did ;)
thanks
 
thanks, good luck
 

  last day (15 days later) »