I want to post youtube link in laravel
My controller
if($validator->fails())
{
$userStatus = new Status();
$userStatus -> status_text = $text;
$userStatus -> users_id = Auth::user()->id;
$userStatus -> save();
Flash::success('Your status has been posted');
return redirect(route('class'));
Now i can post a status. But in my status i also want to post a youtube link.
If i post a youtube link its looks like status.what should i do now. how can i define a link in my project.
you must put your anchor tag inside {!! !!} in your blade.
E.g.
{!!youtube video!!}
Related
I am making a blog. I want to concatenate the soon to be post id to the end of the post slug to make it unique but I can't find a way to access the auto increment value which was not sent through my form in request variable.
public function store(Request $request)
{
$this->validate($request, array(
'title' => 'required|max:255',
'body' => 'required'
));
$cleaned = preg_replace('/[^a-zA-Z0-9\s]/', '', $request -> title);
$cleaned = strtolower($cleaned);
$pieces = explode(" ",$cleaned);
$slug = implode("_", $pieces);
$slug = $slug."_". <------; //HERE IS THE PROBLEM
$post = new Post;
$post -> title = $request -> title;
$post -> body = $request -> body;
$post -> slug = $slug;
$post -> save();
Session::flash('success','Post Successful');
return redirect()->route('posts.show', $post->id);
}
You can't reliably get the AUTO_INCREMENT value before saving the $post.
You have to add it afterwards:
$slug = $slug."_";
$post = new Post;
[...]
$post->save();
$post->slug = $slug.$post->id;
$post->save();
The whole idea of including the id in the slug is not ideal. Maybe you should consider using a different approach.
I want to upload with this controller:
if(Input::has('status-text'))
{
$text=e(Input::get('status-text'));
$rules = [
'status_text'=>'required|string',
];
$validator = Validator::make($request->all(), $rules);
if(Input::hasFile('status_image_upload'))
{
$rules['status_image_upload'] = 'image';
$validator = Validator::make($request->all(), $rules);
if($validator->fails())
{
$image = $request->file('status_image_upload');
$imageName = str_random(8).'_'.$image->getClientOriginalName();
$image->move('status_images', $imageName);
$userStatus = new Status();
$userStatus -> class_id = $id;
$userStatus -> status_text = $text;
$userStatus -> image_url = $imageName;
$userStatus -> type = 1;
$userStatus -> users_id = Auth::user()->id;
$userStatus -> save();
Flash::success('Your status has been posted');
return redirect(route('class',['class_id'=>$id]));
}
}
I know this controller will work for upload pdf. But i want to store another colunm pdf_url. Whats why i can view file and pdf in my blade page.
May this help
Don't forget to add 'files'=>'true' to the header of the form
{!! Form::open(array('url'=>'', 'method'=>'post', 'files'=>'true')) !!}
and then in the controller
if ($file = $request->hasFile('image')) {
$file = $request->file('image');
$filename = time() . '.' . $file->getClientOriginalExtension();
$destinationPath = public_path() . '/images/';
$file->move($destinationPath, $filename);
$support->image = $filename;
}
and I suggest you use this package
intervention/image
I have two route. First one not working and 2nd working. If I put 2nd route in first then its working and another not working.
Here is my route:
Route::any('/class',[
'uses'=> 'classroom#getclass',
'as'=>'class',]);
Route::any('/class',[
'uses'=> 'classroom#showclass',
'as'=>'class',]);
Here is my controller:
public function getclass(Request $request)
{
if (Input::has('post_comment'))
{
$status=Input::get('post_comment');
$commentBox=Input::get('comment_text');
$selectedStatus=Status::find($status);
$selectedStatus->comments()->create([
'comment_text'=>$commentBox,
'user_id'=>Auth::user()->id,
'status_id'=>$status
]);
Flash::message('Your comments has been posted');
return redirect(route('class'));
}
if(Input::has('status-text'))
{
$text=e(Input::get('status-text'));
$rules = [
'status_text'=>'required|string',
];
$validator = Validator::make($request->all(), $rules);
if(Input::hasFile('status_image_upload'))
{
$rules['status_image_upload'] = 'image';
$validator = Validator::make($request->all(), $rules);
if($validator->fails())
{
$image = $request->file('status_image_upload');
$imageName = str_random(8).'_'.$image->getClientOriginalName();
$image->move('status_images', $imageName);
$userStatus = new Status();
$userStatus -> status_text = $text;
$userStatus -> image_url = $imageName;
$userStatus -> type = 1;
$userStatus -> users_id = Auth::user()->id;
$userStatus -> save();
Flash::success('Your status has been posted');
return redirect(route('class'));
}
}
else if ($validator->fails())
{
$userStatus = new Status();
$userStatus -> status_text = $text;
$userStatus -> video_url = $request['video_url'];
$userStatus -> type = 2;
$userStatus -> users_id = Auth::user()->id;
$userStatus -> save();
Flash::success('Your status has been posted');
return redirect(route('classroom'));
}
}
return view('class',[
'posts'=>status::orderBy('id','DESC')->get()
]);}
Another one
public function showclass(Request $request)
{
$randomnumber = rand(50001,1000000);
$classrooms = new Classrooms();
$classrooms->class_name = $request['class_name'];
$classrooms->subject_name = $request['subject_name'];
$classrooms->section = $request['section'];
$classrooms->class_code = $randomnumber;
$classrooms -> user_id = Auth::user()->id;
$classrooms -> save();
return view('class', array('class' => Auth::user()) );
}
What Should to do now? i think my tow url is same that is the problem.If i am right then how can i solve this problem?
The issue is that you are using Route::any().
As the name suggests, it will accept any request (POST, GET, PUT, PATCH, DELETE) to the /class URI and process that with the given controller function.
In your case, when you have this first:
Route::any('/class',[
'uses'=> 'classroom#getclass',
'as'=>'class',]);
Any request to to /class is just being processed by getClass, including your form submission.
And it works fine when you put the other first as that is the first one being used.
Try changing Route::any() to the type of request they actually get.
For example, something like this:
Route::get('/class',[
'uses'=> 'classroom#getclass',
'as'=>'class',]);
Route::post('/class',[
'uses'=> 'classroom#showclass',
'as'=>'class',]);
** NOTE: you cannot use the same URI (e.g /class) for two of the same method types (e.g GET) as the first route would always match first and be used.
I'm trying to create a pdf using laravel 5 and https://github.com/elibyy/laravel-tcpdf
Is there a way to load view and passing data to the view?
something like
$pdf = new TCPDF();
$pdf -> SetPrintHeader(false);
$pdf -> SetPrintFooter(false);
$pdf -> loadView('pdf.invoice',$data); //
$pdf -> Output(storage_path().'/pdf/file.pdf', 'I');
thanks.
Try using
$pdf->writeHTML(view('your.view')->render());
However, the functionnalities of writeHTML() method are limited, see TCPDF documentation.
http://www.tcpdf.org/doc/code/classTCPDF.html#ac3fdf25fcd36f1dce04f92187c621407
Try using
$view = \View::make('myview_name',compact('dynamic_data'));
$html = $view->render();
$pdf = new TCPDF();
$pdf::SetTitle('Hello World');
$pdf::AddPage();
$pdf::writeHTML($html, true, false, true, false, '');
$pdf::Output('hello_world.pdf');
I am new in facebook application,i am try to change code from fbml to graph api but graph api redirecting not working, it shows 404 page not found.My canvas type is FBML.How can I change canvas type FBML to iframe.
My code is,
<?php function index()
{
$facebook = new Facebook(array(
'appId' => '1670025435555',
'secret' => '682018907e58d7208d9b663d9073op09',
'cookie' => true,
));
$session = $facebook->getSession();
$app_id = "1670025435555";
$canvas_page = "http://apps.facebook.com/englishlanguageclub/";
$auth_url = "http://www.facebook.com/dialog/oauth?client_id=". $app_id . "&redirect_uri=" . urlencode($canvas_page)."&scope=user_about_me,user_hometown,email,read_requests,read_stream,publish_stream,user_birthday,sms";
if(isset($_REQUEST["signed_request"]))
{
$signed_request = $_REQUEST["signed_request"];
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
}
if (empty($data["user_id"]))
{
echo("<script type='text/javascript'> top.location.href='" . $auth_url . "'</script>");
}
else
{
$uid = $data["user_id"];
}
}
?>
Anyone please help me...
You have to change the canvas type from the Facebook app settings. You need to login in developer.facebook.com and then go to your App and then Edit the settings.