How to display "." in Yajra Datatable Laravel infyom - laravel-5

I am working on Laravel Infyom generator. Every thing is working perfectly for me. My requirement is display "." , in header of datatable.
private function getColumns()
is responsible for display headers but when i use "Dept.No" then it is display in datatbale "Dept No". I want "." also.

protected function getColumns()
{
return [
'id' => ['title' => 'Código'],
'nome' => ['title' => 'Nome do Produto'],
'grupo' => ['title' => 'Grupo'],
'estoque' => ['title' => 'Estoque'],
'preco' => ['title' => 'Preço de Venda'],
'custo' => ['title' => 'Preço de Custo'],
'ativo' => ['title' => 'Ativo?'],
'created_at' => ['title' => 'Dt. Cadastro']
];
}

Related

Method Illuminate\Validation\Validator::validateDocs does not exist

This issue appears after I submit a form and run form validation, even though my form validation is functioning on another page in that file.
Method Illuminate\Validation\Validator::validateDocs does not exist.
public function store(Request $request) {
$request->validate([
'title' => 'required',
'category' => 'required',
'content' => 'required|min:50',
'file' => 'required|docs|mimes:txt,pdf,ppt|max:2048'
$docsName = time() . '.'. $request->file->extension();
// $request->docs->move(public_path('docs'), $docsName);
$request->file->storeAs('public/docs', $docsName);
$postData = ['title' => $request->title, 'category' => $request->category, 'content' => $request->content, 'docs' => $docsName];
Post::create($postData);
return redirect('/post')->with(['message' => 'Post added successfully!', 'status' => 'success']);
}

Why does an inertia route change?

In a Laravel/Inertia application, I try to store vinylRecords.
Therefore I created a vinylRecords resource.
Route::resource('vinylRecords', VinylRecordController::class)->only(['index', 'create','store', 'edit', 'update']);
In the frontend, the store function looks like:
methods: {
submitForm() {
this.$inertia.post(route("vinylRecords.store"), this.form, {
onSuccess: (response) => {
alert(Object.keys(response.props))
this.form.reset();
},
});
}
},
Sometimes, the routing is right and the Laravel stores the new record. But most of time, Laravel redirects to the index method without storing the data.
The store method:
public function store(StoreVinylRecordRequest $request)
{
$data = $request->validated();
$record = VinylRecord::create($data);
$record->labels()->sync($data['label_ids']);
$record->styles()->sync($data['style_ids']);
$record->specials()->sync($data['special_ids']);
return Inertia::render('vinylRecord/index', [
'records' => VinylRecordResource::collection(VinylRecord::all()),
'vinylRecordId' => $record->id
]);
}
To solve the problem, I created a new controller with a new route to store the data:
Route::post('storeVinylRecord', [StoreVinylRecordController::class, 'store'])->name('storeVinylRecord');
But the problem was the same.
How is it possible, that the routing changes from one request to the other? Is there an big error in the code from my side?
Edited: Add the StoreVinylRecordRequest
public function rules()
{
return [
'artist' => 'required|string',
'title' => 'required|string',
'barcode' => 'nullable|integer',
'genre_id' => 'nullable|integer',
'country' => 'nullable',
'year' => 'nullable|integer',
'label_ids' => 'nullable',
'style_ids' => 'nullable',
'special_ids' => 'nullable',
'thumb' => 'nullable|string',
'cover_image' => 'nullable|string',
'quantity' => 'nullable|integer',
'speed' => 'nullable|integer',
'part_type' => 'nullable|string',
'storage_location' => 'nullable|string',
'supplier_id' => 'nullable|in:suppliers,id',
'purchasing_price' => 'nullable|numeric',
'selling_price' => 'nullable|numeric',
];
}

mutiple emails controller is not working how do i solve?

i have a problem this controller is not working how can i do? should send mutiple emails how do i solve?
I don't know how to handle it
function submit(Request $request) {
$this->validate($request, [
'email' => 'required|email',
'file' => 'mimes:pdf,doc,docx'
]);
$data = array(
'name' => $request->name,
'cognome' => $request->cognome,
'luogo' => $request->luogo,
'date' => $request->date,
'telefono' => $request->telefono,
'email' => $request->email,
'citta' => $request->citta,
'provincia' => $request->provincia,
'studio' => $request->studio,
'lingua' => $request->lingua,
'livello' => $request->livello,
'lingua2' => $request->lingua2,
'livello2' => $request->livello2,
'file' => $request->file,
'agree' => $request->agree
);
Mail::send('mail', $data, function($message) use ($request,$data){
$message->to('luis#gmail.com', 'luis')->subject('Send mail ' . $request->name);
$message->from($request->email, $request->name);
if($request->hasFile('file')){
$message->attach($request->file('file')->getRealPath(), array(
'as' => $request->file('file')->getClientOriginalName(),
'mime' => $request->file('file')->getMimeType())
);
}
});
Session::flash('success', 'Mail spedita con sucesso');
}
I wish I could solve the problem
any advice? on how to do it?

Laravel mail blade passing a variable

I need to pass some variables to my sending email.
Here is my code:
$data = [
'first' => $request->first,
'last' => $request->last,
'business_org' => $request->business_org,
'instagram' => $request->instagram,
'email' => $request->email,
'phone' => $request->phone,
'unique' => $request->unique,
'purchased' => $request->products_purchased,
'city' => $request->city,
'state' => $request->state,
'filename' => $fileName
];
// send email with details
Mail::send('emails.justshoot', $data, function($message) {
$message->from('us#something.com', 'Just Shoot Upload');
$message->to('myemail#gmail.com')->cc('myemail#gmail.com');
});
I then attempt to access the variable so I can display it in my email.
emails.justshoot.blade.php
{{$data}} gives an error. What am I doing wrong?
You are totally fine with what you are doing, but the second param is the data to pass to the view, and as with the with([]) method to call the view, the array passed will generate an object for each entry, and so with what you are doing you are generating $first, $last, $business_org and the $data is just the name of the array, so it isn't been passed as element to the view: if you want this, you should pass [$data] to the mail send :
$data = [
'first' => $request->first,
'last' => $request->last,
'business_org' => $request->business_org,
'instagram' => $request->instagram,
'email' => $request->email,
'phone' => $request->phone,
'unique' => $request->unique,
'purchased' => $request->products_purchased,
'city' => $request->city,
'state' => $request->state,
'filename' => $fileName
];
// send email with details
Mail::send('emails.justshoot', [$data], function($message) {
$message->from('us#something.com', 'Just Shoot Upload');
$message->to('myemail#gmail.com')->cc('myemail#gmail.com');
});
and then in the view you can do {{$data}}
TIPS: You should create a mail with php artisan and then you are able to do whatever you want, in a more elegant way

Using isDirty in Laravel

I'm using the isDirty() method in my controller to check if any field is changed. Then I am saving the old data of a field and the new data in a table. The code is working fine; however, how can I optimize this code?
By using the below code, I will have to write each field name again and again. If request->all() has 20 fields, but I want to check six fields if they are modified, how can I pass only 6 fields in the below code, without repeating?
Controller
if ($teacher->isDirty('field1')) {
$new_data = $teacher->field1;
$old_data = $teacher->getOriginal('field1');
DB::table('teacher_logs')->insert(
[
'user_id' => $user->id,
'teacher_id' => $teacher->id,
'old_value' => $old_data,
'new_value' => $new_data,
'column_changed' => "First Name",
]);
}
You can set a list of what fields you want to be checking for then you can loop through the dirty fields and build your insert records.
use Illuminate\Support\Arr;
...
$fields = [
'field1' => 'First Name',
'field2' => '...',
...
];
$dirtied = Arr::only($teacher->getDirty(), array_keys($fields));
$inserts = [];
foreach ($dirtied as $key => $value) {
$inserts[] = [
'user_id' => $user->id,
'teacher_id' => $teacher->id,
'old_value' => $teacher->getOriginal($key),
'new_value' => $value,
'column_changed' => $fields[$key];
];
}
DB::table(...)->insert($inserts);
i tried following code after getting idea by lagbox in comments, and i have found solution to my problem.
$dirty = $teacher->getDirty('field1','field2','field3');
foreach ($dirty as $field => $newdata)
{
$olddata = $teacher->getOriginal($field);
if ($olddata != $newdata)
{
DB::table('teacher_logs')->insert(
['user_id' => $user->id,
'teacher_id' => $teacher->id,
'old_value' => $olddata,
'new_value' => $newdata,
'column_changed' => "changed",
]);
}
}

Resources